gpt4 book ai didi

php - 如何在 php 中解码 TripleDESCryptoService 字符串?

转载 作者:可可西里 更新时间:2023-11-01 13:27:37 24 4
gpt4 key购买 nike

下面的代码在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 脚本中。谢谢。

最佳答案

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

关于php - 如何在 php 中解码 TripleDESCryptoService 字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36316200/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com