将 c# TripleDes PKCS7 代码转换为 php 代码

convert c# TripleDes PKCS7 code to php code

我在 C# 中有这段代码

var dataBytes = Encoding.UTF8.GetBytes('clear text');

var symmetric = SymmetricAlgorithm.Create("TripleDes");
symmetric.Mode = CipherMode.ECB;
symmetric.Padding = PaddingMode.PKCS7;

var encryptor = symmetric.CreateEncryptor(Convert.FromBase64String('myKey'), new byte[8]);

var signedData = Convert.ToBase64String(encryptor.TransformFinalBlock(dataBytes, 0, dataBytes.Length));

现在我需要将 C# 代码转换为 php 代码。 重视

我使用这个功能并为我工作

function encryptData($plainText,$key)
{

    $byte = mb_convert_encoding($key, 'ASCII');

    $desKey = base64_decode($key);
    $data = mb_convert_encoding($plainText, 'ASCII');

    // add PKCS#7 padding
    $blocksize = mcrypt_get_block_size('tripledes', 'ecb');
    $paddingSize = $blocksize - (strlen($data) % $blocksize);
    $data .= str_repeat(chr($paddingSize), $paddingSize);

    // encrypt password
    $encData = mcrypt_encrypt('tripledes', $desKey, $data, 'ecb');

    return base64_encode($encData);
}