netphp加密
因項目需要,需要與對方的介面對接 ,對方是.net開發的,需要與我們的php對接,但是php 3des加密後,.net的無法解析,且加密後的字串與.net加密後的字串,前半部分一樣,後半部分就不一樣!,也就是說加密後的字串不相等,有高手嗎,高分求解?
.net程式:
public static string Encrypt3DES(string a_strString, string a_strKey)
{
TripleDESCryptoServiceProvider DES = new TripleDESCryptoServiceProvider();
DES.Key = ASCIIEncoding.ASCII.GetBytes(a_strKey);
DES.Mode = CipherMode.ECB;
ICryptoTransform DESEncrypt = DES.CreateEncryptor();
byte[] Buffer = ASCIIEncoding.ASCII.GetBytes(a_strString);
return Convert.ToBase64String(DESEncrypt.TransformFinalBlock(Buffer, 0, Buffer.Length));
}
我寫的php加密程度:
function encrypt($string) {
$key = "05217c03d7b74fe581fc449b";
$cipher_alg = MCRYPT_TRIPLEDES;
$iv = mcrypt_create_iv(mcrypt_get_iv_size($cipher_alg,MCRYPT_MODE_ECB), MCRYPT_RAND);
$encrypted_string = mcrypt_encrypt($cipher_alg, $key, $string, MCRYPT_MODE_ECB, $iv);
return base64_encode($encrypted_string);//轉化成16進位
}