标签:lock tor transform encoding pre byte hash base har
private static string Encrypt2(string str, string sKey)
{
string s = "";
using (System.Security.Cryptography.DESCryptoServiceProvider des = new System.Security.Cryptography.DESCryptoServiceProvider())
{
using (System.Security.Cryptography.Rfc2898DeriveBytes rfc2898 = new System.Security.Cryptography.Rfc2898DeriveBytes(sKey, new System.Security.Cryptography.MD5CryptoServiceProvider().ComputeHash(Encoding.Default.GetBytes(sKey))))
{
des.Key = rfc2898.GetBytes(des.KeySize / 8);
des.IV = rfc2898.GetBytes(des.BlockSize / 8);
}
byte[] input = Encoding.Default.GetBytes(str);
s = Convert.ToBase64String(des.CreateEncryptor().TransformFinalBlock(input, 0, input.Length));
}
return s;
}
private string DecryptByDES(string encrypted, string key, string iv)
{
string s = "";
using (System.Security.Cryptography.DESCryptoServiceProvider des =
new System.Security.Cryptography.DESCryptoServiceProvider())
{
using (System.Security.Cryptography.Rfc2898DeriveBytes rfc2898 =
new System.Security.Cryptography.Rfc2898DeriveBytes(key,
new System.Security.Cryptography.MD5CryptoServiceProvider().ComputeHash(
Encoding.Default.GetBytes(key))))
{
des.Key = rfc2898.GetBytes(des.KeySize / 8);
des.IV = rfc2898.GetBytes(des.BlockSize / 8);
}
byte[] input = Convert.FromBase64String(encrypted);
s = Encoding.Default.GetString(des.CreateDecryptor().TransformFinalBlock(input, 0, input.Length));
}
return s;
}
标签:lock tor transform encoding pre byte hash base har
原文地址:https://www.cnblogs.com/honk/p/14600625.html