C++ 植物学C++;。如何解密ssh数据包?
我正在尝试用您的库实现SSH协议。我尝试在cbc模式下使用3des算法 我按如下方式创建加密:C++ 植物学C++;。如何解密ssh数据包?,c++,ssh,botan,C++,Ssh,Botan,我正在尝试用您的库实现SSH协议。我尝试在cbc模式下使用3des算法 我按如下方式创建加密: _encrypt.reset(new Pipe(encryptFilter = new CBC_Encryption(cipher->clone(), new Null_Padding, c2s_key, c2s_iv)));` _decrypt.reset(new Pipe(decryptFilter = new CBC_Decryption(cipher->clone(), new
_encrypt.reset(new Pipe(encryptFilter = new CBC_Encryption(cipher->clone(), new Null_Padding, c2s_key, c2s_iv)));`
_decrypt.reset(new Pipe(decryptFilter = new CBC_Decryption(cipher->clone(), new Null_Padding, s2c_key, s2c_iv)));
bool crypto::decryptPacket(Botan::SecureVector<Botan::byte> &decrypted, Botan::SecureVector<Botan::byte> &packet, uint32_t len)
{
uint32_t pLen = packet.size();
if (pLen % _decryptBlock != 0)
{
len = pLen + (pLen % _decryptBlock);
}
for (uint32_t pktIndex = 0; pktIndex < len; pktIndex += _decryptBlock)
{
Botan::SecureVector<Botan::byte> e(packet.begin() + pktIndex, packet.size() + pktIndex + _decryptBlock);
_decrypt->process_msg(e, _decryptBlock);
decrypted += _decrypt->read_all(_decrypt->message_count() - 1);
}
return true;
}
bool crypto::encryptPacket(Botan::SecureVector<Botan::byte> &crypted, Botan::SecureVector<Botan::byte> &hmac, Botan::SecureVector<Botan::byte> &packet, uint32_t seq)
{
SecureVector<Botan::byte> macStr;
uint32_t nSeq = (uint32_t)htonl(seq);
_encrypt->start_msg();
_encrypt->write(packet.begin(), packet.size());
_encrypt->end_msg();
crypted = _encrypt->read_all(_encrypt->message_count() - 1);
if (_hmacOut)
{
macStr = SecureVector<Botan::byte>((Botan::byte*)&nSeq, 4);
macStr += packet;
hmac = _hmacOut->process(macStr);
}
return true;
}
bool crypto::encryptPacket(Botan::SecureVector<Botan::byte> &crypted, Botan::SecureVector<Botan::byte> &hmac, Botan::SecureVector<Botan::byte> &packet, uint32_t seq)
{
SecureVector<Botan::byte> macStr;
uint32_t nSeq = (uint32_t)htonl(seq);
_encrypt->start_msg();
_encrypt->write(packet.begin(), packet.size());
_encrypt->end_msg();
crypted = _encrypt->read_all(_encrypt->message_count() - 1);
if (_hmacOut)
{
macStr = SecureVector<Botan::byte>((Botan::byte*)&nSeq, 4);
macStr += packet;
hmac = _hmacOut->process(macStr);
}
return true;
}
我按如下方式创建解密:
_encrypt.reset(new Pipe(encryptFilter = new CBC_Encryption(cipher->clone(), new Null_Padding, c2s_key, c2s_iv)));`
_decrypt.reset(new Pipe(decryptFilter = new CBC_Decryption(cipher->clone(), new Null_Padding, s2c_key, s2c_iv)));
bool crypto::decryptPacket(Botan::SecureVector<Botan::byte> &decrypted, Botan::SecureVector<Botan::byte> &packet, uint32_t len)
{
uint32_t pLen = packet.size();
if (pLen % _decryptBlock != 0)
{
len = pLen + (pLen % _decryptBlock);
}
for (uint32_t pktIndex = 0; pktIndex < len; pktIndex += _decryptBlock)
{
Botan::SecureVector<Botan::byte> e(packet.begin() + pktIndex, packet.size() + pktIndex + _decryptBlock);
_decrypt->process_msg(e, _decryptBlock);
decrypted += _decrypt->read_all(_decrypt->message_count() - 1);
}
return true;
}
bool crypto::encryptPacket(Botan::SecureVector<Botan::byte> &crypted, Botan::SecureVector<Botan::byte> &hmac, Botan::SecureVector<Botan::byte> &packet, uint32_t seq)
{
SecureVector<Botan::byte> macStr;
uint32_t nSeq = (uint32_t)htonl(seq);
_encrypt->start_msg();
_encrypt->write(packet.begin(), packet.size());
_encrypt->end_msg();
crypted = _encrypt->read_all(_encrypt->message_count() - 1);
if (_hmacOut)
{
macStr = SecureVector<Botan::byte>((Botan::byte*)&nSeq, 4);
macStr += packet;
hmac = _hmacOut->process(macStr);
}
return true;
}
bool crypto::encryptPacket(Botan::SecureVector<Botan::byte> &crypted, Botan::SecureVector<Botan::byte> &hmac, Botan::SecureVector<Botan::byte> &packet, uint32_t seq)
{
SecureVector<Botan::byte> macStr;
uint32_t nSeq = (uint32_t)htonl(seq);
_encrypt->start_msg();
_encrypt->write(packet.begin(), packet.size());
_encrypt->end_msg();
crypted = _encrypt->read_all(_encrypt->message_count() - 1);
if (_hmacOut)
{
macStr = SecureVector<Botan::byte>((Botan::byte*)&nSeq, 4);
macStr += packet;
hmac = _hmacOut->process(macStr);
}
return true;
}
我尝试按如下方式解密:
_encrypt.reset(new Pipe(encryptFilter = new CBC_Encryption(cipher->clone(), new Null_Padding, c2s_key, c2s_iv)));`
_decrypt.reset(new Pipe(decryptFilter = new CBC_Decryption(cipher->clone(), new Null_Padding, s2c_key, s2c_iv)));
bool crypto::decryptPacket(Botan::SecureVector<Botan::byte> &decrypted, Botan::SecureVector<Botan::byte> &packet, uint32_t len)
{
uint32_t pLen = packet.size();
if (pLen % _decryptBlock != 0)
{
len = pLen + (pLen % _decryptBlock);
}
for (uint32_t pktIndex = 0; pktIndex < len; pktIndex += _decryptBlock)
{
Botan::SecureVector<Botan::byte> e(packet.begin() + pktIndex, packet.size() + pktIndex + _decryptBlock);
_decrypt->process_msg(e, _decryptBlock);
decrypted += _decrypt->read_all(_decrypt->message_count() - 1);
}
return true;
}
bool crypto::encryptPacket(Botan::SecureVector<Botan::byte> &crypted, Botan::SecureVector<Botan::byte> &hmac, Botan::SecureVector<Botan::byte> &packet, uint32_t seq)
{
SecureVector<Botan::byte> macStr;
uint32_t nSeq = (uint32_t)htonl(seq);
_encrypt->start_msg();
_encrypt->write(packet.begin(), packet.size());
_encrypt->end_msg();
crypted = _encrypt->read_all(_encrypt->message_count() - 1);
if (_hmacOut)
{
macStr = SecureVector<Botan::byte>((Botan::byte*)&nSeq, 4);
macStr += packet;
hmac = _hmacOut->process(macStr);
}
return true;
}
bool crypto::encryptPacket(Botan::SecureVector<Botan::byte> &crypted, Botan::SecureVector<Botan::byte> &hmac, Botan::SecureVector<Botan::byte> &packet, uint32_t seq)
{
SecureVector<Botan::byte> macStr;
uint32_t nSeq = (uint32_t)htonl(seq);
_encrypt->start_msg();
_encrypt->write(packet.begin(), packet.size());
_encrypt->end_msg();
crypted = _encrypt->read_all(_encrypt->message_count() - 1);
if (_hmacOut)
{
macStr = SecureVector<Botan::byte>((Botan::byte*)&nSeq, 4);
macStr += packet;
hmac = _hmacOut->process(macStr);
}
return true;
}
bool crypto::decryptPacket(Botan::SecureVector&decrypted,Botan::SecureVector&packet,uint32)
{
uint32_t pLen=packet.size();
如果(pLen%\u解密块!=0)
{
len=正压送风系统+(正压送风系统%);
}
对于(uint32\u t pktIndex=0;pktIndex处理消息(e,解密块);
解密+=\u解密->全部读取(\u解密->消息\u计数()-1);
}
返回true;
}
我尝试如下加密:
_encrypt.reset(new Pipe(encryptFilter = new CBC_Encryption(cipher->clone(), new Null_Padding, c2s_key, c2s_iv)));`
_decrypt.reset(new Pipe(decryptFilter = new CBC_Decryption(cipher->clone(), new Null_Padding, s2c_key, s2c_iv)));
bool crypto::decryptPacket(Botan::SecureVector<Botan::byte> &decrypted, Botan::SecureVector<Botan::byte> &packet, uint32_t len)
{
uint32_t pLen = packet.size();
if (pLen % _decryptBlock != 0)
{
len = pLen + (pLen % _decryptBlock);
}
for (uint32_t pktIndex = 0; pktIndex < len; pktIndex += _decryptBlock)
{
Botan::SecureVector<Botan::byte> e(packet.begin() + pktIndex, packet.size() + pktIndex + _decryptBlock);
_decrypt->process_msg(e, _decryptBlock);
decrypted += _decrypt->read_all(_decrypt->message_count() - 1);
}
return true;
}
bool crypto::encryptPacket(Botan::SecureVector<Botan::byte> &crypted, Botan::SecureVector<Botan::byte> &hmac, Botan::SecureVector<Botan::byte> &packet, uint32_t seq)
{
SecureVector<Botan::byte> macStr;
uint32_t nSeq = (uint32_t)htonl(seq);
_encrypt->start_msg();
_encrypt->write(packet.begin(), packet.size());
_encrypt->end_msg();
crypted = _encrypt->read_all(_encrypt->message_count() - 1);
if (_hmacOut)
{
macStr = SecureVector<Botan::byte>((Botan::byte*)&nSeq, 4);
macStr += packet;
hmac = _hmacOut->process(macStr);
}
return true;
}
bool crypto::encryptPacket(Botan::SecureVector<Botan::byte> &crypted, Botan::SecureVector<Botan::byte> &hmac, Botan::SecureVector<Botan::byte> &packet, uint32_t seq)
{
SecureVector<Botan::byte> macStr;
uint32_t nSeq = (uint32_t)htonl(seq);
_encrypt->start_msg();
_encrypt->write(packet.begin(), packet.size());
_encrypt->end_msg();
crypted = _encrypt->read_all(_encrypt->message_count() - 1);
if (_hmacOut)
{
macStr = SecureVector<Botan::byte>((Botan::byte*)&nSeq, 4);
macStr += packet;
hmac = _hmacOut->process(macStr);
}
return true;
}
bool crypto::encryptPacket(Botan::SecureVector&crypted,Botan::SecureVector&hmac,Botan::SecureVector&packet,uint32_t seq)
{
安全载体macStr;
uint32_t nSeq=(uint32_t)htonl(seq);
_加密->启动消息();
_加密->写入(packet.begin(),packet.size());
_加密->结束消息();
crypted=\u encrypt->read\u all(\u encrypt->message\u count()-1);
如果(hmacOut)
{
macStr=SecureVector((植物学::字节*)&nSeq,4);
macStr+=数据包;
hmac=\u hmacOut->process(macStr);
}
返回true;
}
我尝试如下加密:
_encrypt.reset(new Pipe(encryptFilter = new CBC_Encryption(cipher->clone(), new Null_Padding, c2s_key, c2s_iv)));`
_decrypt.reset(new Pipe(decryptFilter = new CBC_Decryption(cipher->clone(), new Null_Padding, s2c_key, s2c_iv)));
bool crypto::decryptPacket(Botan::SecureVector<Botan::byte> &decrypted, Botan::SecureVector<Botan::byte> &packet, uint32_t len)
{
uint32_t pLen = packet.size();
if (pLen % _decryptBlock != 0)
{
len = pLen + (pLen % _decryptBlock);
}
for (uint32_t pktIndex = 0; pktIndex < len; pktIndex += _decryptBlock)
{
Botan::SecureVector<Botan::byte> e(packet.begin() + pktIndex, packet.size() + pktIndex + _decryptBlock);
_decrypt->process_msg(e, _decryptBlock);
decrypted += _decrypt->read_all(_decrypt->message_count() - 1);
}
return true;
}
bool crypto::encryptPacket(Botan::SecureVector<Botan::byte> &crypted, Botan::SecureVector<Botan::byte> &hmac, Botan::SecureVector<Botan::byte> &packet, uint32_t seq)
{
SecureVector<Botan::byte> macStr;
uint32_t nSeq = (uint32_t)htonl(seq);
_encrypt->start_msg();
_encrypt->write(packet.begin(), packet.size());
_encrypt->end_msg();
crypted = _encrypt->read_all(_encrypt->message_count() - 1);
if (_hmacOut)
{
macStr = SecureVector<Botan::byte>((Botan::byte*)&nSeq, 4);
macStr += packet;
hmac = _hmacOut->process(macStr);
}
return true;
}
bool crypto::encryptPacket(Botan::SecureVector<Botan::byte> &crypted, Botan::SecureVector<Botan::byte> &hmac, Botan::SecureVector<Botan::byte> &packet, uint32_t seq)
{
SecureVector<Botan::byte> macStr;
uint32_t nSeq = (uint32_t)htonl(seq);
_encrypt->start_msg();
_encrypt->write(packet.begin(), packet.size());
_encrypt->end_msg();
crypted = _encrypt->read_all(_encrypt->message_count() - 1);
if (_hmacOut)
{
macStr = SecureVector<Botan::byte>((Botan::byte*)&nSeq, 4);
macStr += packet;
hmac = _hmacOut->process(macStr);
}
return true;
}
bool crypto::encryptPacket(Botan::SecureVector&crypted,Botan::SecureVector&hmac,Botan::SecureVector&packet,uint32_t seq)
{
安全载体macStr;
uint32_t nSeq=(uint32_t)htonl(seq);
_加密->启动消息();
_加密->写入(packet.begin(),packet.size());
_加密->结束消息();
crypted=\u encrypt->read\u all(\u encrypt->message\u count()-1);
如果(hmacOut)
{
macStr=SecureVector((植物学::字节*)&nSeq,4);
macStr+=数据包;
hmac=\u hmacOut->process(macStr);
}
返回true;
}
因此,加密的数据包通常都是加密的,但当我尝试解密第二个数据包和下一个数据包时,第一个数据包被错误地解密。有什么问题