netphp encryption
Because the project needs, need to interface with the other side, the other side is. NET developed, need to connect with our PHP, but after PHP 3DES encryption,. NET cannot be resolved, and the encrypted string with. NET encrypted string, the first half of the same, the second half is not the same! , that is, the string is not equal after the encryption, a master, high-score solution?
. NET programs:
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));
}
I wrote the level of PHP encryption:
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);//Convert to 16 binary
}