欧洲中央银行在C#的Des和3Des(来自C)
我有这个C代码,我必须用C写 如何用C#编写这些ecb des和3des函数欧洲中央银行在C#的Des和3Des(来自C),c#,c,converter,des,3des,C#,C,Converter,Des,3des,我有这个C代码,我必须用C写 如何用C#编写这些ecb des和3des函数 我问这个问题是因为有很多方法可以做到这一点,我必须确保使用相同的加密参数。为什么不直接使用System.Security.Cryptography中的TripledScryptoServiceProvider public static string Encrypt(string data, string pKey) { TripleDESCryptoServiceProvider cryptor = new
我问这个问题是因为有很多方法可以做到这一点,我必须确保使用相同的加密参数。为什么不直接使用
System.Security.Cryptography
中的TripledScryptoServiceProvider
public static string Encrypt(string data, string pKey)
{
TripleDESCryptoServiceProvider cryptor = new TripleDESCryptoServiceProvider();
byte[] array = null;
cryptor.Key = pKey;
cryptor.Mode = CipherMode.ECB;
ICryptoTransform encrypt = cryptor.CreateEncryptor();
array = ASCIIEncoding.ASCII.GetBytes(data);
string retVal = "";
retVal = Convert.ToBase64String(encrypt.TransformFinalBlock(array, 0, array.Length));
return retVal;
}
对于解密,使用相同的逻辑,但调用CreateDecryptor()
public static string Encrypt(string data, string pKey)
{
TripleDESCryptoServiceProvider cryptor = new TripleDESCryptoServiceProvider();
byte[] array = null;
cryptor.Key = pKey;
cryptor.Mode = CipherMode.ECB;
ICryptoTransform encrypt = cryptor.CreateEncryptor();
array = ASCIIEncoding.ASCII.GetBytes(data);
string retVal = "";
retVal = Convert.ToBase64String(encrypt.TransformFinalBlock(array, 0, array.Length));
return retVal;
}