我刚刚使用pyCrypto轻松加密了数据字符串,但是不知道如何在crypto中解密它.任何人都可以帮助使用C语言编写带有密码的示例解密代码吗?
这是我的python代码:
key = '0123456789abcdef'
data = "aaaaaaaaaaaaaaaa"
iv = ''.join(chr(random.randint(0, 0xFF)) for i in range(16))
encryptor = AES.new(key, AES.MODE_CBC, iv)
enc = encryptor.encrypt(data)
解决方法:
这段代码来自2005年的示例,但是应该为您提供一个良好的起点:
std::string ciphertext = "..."; // what Python encryption produces
std::string decryptedtext;
byte key[ CryptoPP::AES::DEFAULT_KEYLENGTH ], iv[ CryptoPP::AES::BLOCKSIZE ];
// populate key and iv with the correct values
CryptoPP::AES::Decryption aesDecryption(key, CryptoPP::AES::DEFAULT_KEYLENGTH);
CryptoPP::CBC_Mode_ExternalCipher::Decryption cbcDecryption( aesDecryption, iv );
CryptoPP::StreamTransformationFilter stfDecryptor(cbcDecryption, new CryptoPP::StringSink( decryptedtext ) );
stfDecryptor.Put( reinterpret_cast<const unsigned char*>( ciphertext.c_str() ), ciphertext.size() );
stfDecryptor.MessageEnd();
// it's all in decryptedText now