时间:2021-07-01 10:21:17 帮助过:8人阅读
$cipher = mcrypt_module_open(MCRYPT_BLOWFISH, '', MCRYPT_MODE_ECB, '');
$iv = '00000000';
$key = "strkey11";
$stext = '38A0E9312DDA8F7C16B9A12159168C76';
$stext = md5($stext, true);
//经过调试知道,在这时$stext的值与C++中MD5后的结果一致
if (mcrypt_generic_init($cipher, $key, $iv) != -1)
{
$dtext = mcrypt_generic($cipher,$stext );
mcrypt_generic_deinit($cipher);
// Display the result in hex.
printf("blowfish encrypted:
%s
",strtoupper(bin2hex($dtext)));
}
mcrypt_module_close($cipher);
MD5_CTX md5;
unsigned char str[16];
md5.MD5String(strSource.c_str() ,str);
BlockCipher *bf;
char key[] = "strkey11"; //Key
bf = new BlowFish();
bf->setKey((void *)key, 8*8);
bf->encrypt((void *)str, 8); //unsigned char str[16];
bf->encrypt((void *)(str+8), 8);
char temp1[4] = {0};
char buff1[128] = {0};
for(int i = 0;i<16;i++)
{
sprintf(temp1,"%02x",str[i]);
strcat(buff1,temp1);
}
AnsiString strResult = String(buff1).UpperCase();
delete bf;