我正在尝试将此加密和解密功能从C#转换为php
public static string EncryptBySymmetricKey(string text, string sek) {
//Encrypting SEK
try {
byte[] dataToEncrypt = Convert.FromBase64String(text);
var keyBytes = Convert.FromBase64String(sek);
AesManaged tdes = new AesManaged();
tdes.KeySize = 256;
tdes.BlockSize = 128;
tdes.Key = keyBytes;
tdes.Mode = CipherMode.ECB;
tdes.Padding = PaddingMode.PKCS7;
ICryptoTransform encrypt__1 = tdes.CreateEncryptor();
byte[] deCipher = encrypt__1.TransformFinalBlock(dataToEncrypt, 0, dataToEncrypt.Length);
tdes.Clear();
string EK_result = Convert.ToBase64String(deCipher);
return EK_result;
}
catch(Exception ex) {
throw ex;
}
}
public static byte[] DecryptBySymmetricKey(string encryptedText, byte[] key) {
//Decrypting SEK
try {
byte[] dataToDecrypt = Convert.FromBase64String(encryptedText);
var keyBytes = key;
AesManaged tdes = new AesManaged();
tdes.KeySize = 256;
tdes.BlockSize = 128;
tdes.Key = keyBytes;
tdes.Mode = CipherMode.ECB;
tdes.Padding = PaddingMode.PKCS7;
ICryptoTransform decrypt__1 = tdes.CreateDecryptor();
byte[] deCipher = decrypt__1.TransformFinalBlock(dataToDecrypt, 0, dataToDecrypt.Length);
tdes.Clear();
string EK_result = Convert.ToBase64String(deCipher);
return EK_result;
}
catch(Exception ex) {
throw ex;
}
}
任何人都可以帮助我,上述C#函数的正确php代码是什么。 在这里,我只想要php中相同的C#代码。
预先感谢