首页 文章

我可以解密通过PHP加密的C中的数据吗?

提问于
浏览
2

我正在使用mcrypt_encrypt和base64_encode来加密php中的数据 . 我试过在C中解密数据,但无济于事 . 我有多年来使用的C Rijndael逻辑,以及base64_decode逻辑 . 后者完美地解码由php的base64_encode编码的字符串 . 我正在使用带有php和C的CBC . 我已尝试过不同的块大小等等,但无济于事 . 任何建议都非常感谢 .

这是我的测试逻辑:

PHP

$key = "qwertyuiopasdfghjklzxcvbnmqwerty";  
$iv = "12345678901234561234567890123456";  
$text = "this is the text to encrypt";
$crypttext = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $text, MCRYPT_MODE_CBC, $iv);
echo base64_encode($crypttext)."
";

C

char* base64encode = ".. output from php...";  
unsigned char binaryData[256];  
int binaryNumBytes;  
char result[256];  
base64_decode(reinterpret_cast<unsigned char*>(base64encode), strlen(base64encode),       binaryData, &binaryNumBytes, false);  
Encryption::Rijndael rijndael;  
char* key = "qwertyuiopasdfghjklzxcvbnmqwerty";  
char* iv = "12345678901234561234567890123456";  
rijndael.Init(Encryption::Rijndael::CBC, reinterpret_cast<const char*>(key), 32, 32,    reinterpret_cast<const char*>(iv));  
rijndael.Decrypt(reinterpret_cast<const char*>(binaryData), reinterpret_cast<char*>(result), 32);  
cout << result << endl;

编辑:如果我使用ECB模式,我可以让它工作 . 在CBC之间存在一些问题 .

1 回答

  • 0

    使用ECB模式是可行的方法 .

相关问题