以下代码在VB中解密字符串:
Public Function Desencriptar(ByVal Input As String) As String
Dim IV() As Byte = ASCIIEncoding.ASCII.GetBytes("abcdefgh")
Dim EncryptionKey() As Byte = Convert.FromBase64String("hereGoesTheKey")
Dim buffer() As Byte = Convert.FromBase64String(Input)
Dim des As TripleDESCryptoServiceProvider = New TripleDESCryptoServiceProvider
des.Key = EncryptionKey
des.IV = IV
Return Encoding.UTF8.GetString(des.CreateDecryptor().TransformFinalBlock(buffer, 0, buffer.Length()))
End Function
我想知道如何将此过程复制到移动应用服务的PHP脚本中。感谢。
答案 0 :(得分:2)
this code might help.
<?php
$key = "123456";
function pkcs7_pad($text, $blocksize)
{
$pad = $blocksize - (strlen($text) % $blocksize);
return $text . str_repeat(chr($pad), $pad);
}
$input = pkcs7_pad("test", 16);//16byte
// $key = md5(utf8_encode($key), true);
$td = mcrypt_module_open('tripledes', '', 'ecb', '');//ecb mode
$iv = mcrypt_create_iv (mcrypt_enc_get_iv_size($td), MCRYPT_RAND);
mcrypt_generic_init($td, $key, $iv);
$encrypted_data = mcrypt_generic($td, $input);
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
echo base64_encode($encrypted_data);
?>
请查看此链接以获取更多详细信息3DES