解密函数在这里了,加密函数该如何写呢?
public static string JeMi(string data)
{
if (data == null)
{
throw new ArgumentNullException("data");
}
try
{
string str;
SymmetricAlgorithm algorithm = TDESP();
byte[] buffer = Convert.FromBase64String(data);
MemoryStream stream = new MemoryStream();
CryptoStream stream2 = new CryptoStream(stream, algorithm.CreateDecryptor(), CryptoStreamMode.Write);
try
{
stream2.Write(buffer, 0, buffer.Length);
str = Encoding.UTF8.GetString(stream.ToArray());
int startIndex = str.IndexOf("\r\n", 0, str.Length);
str = str.Remove(startIndex, str.Length - startIndex);
}
finally
{
stream2.Close();
stream.Close();
}
return str;
}
catch (Exception)
{
return null;
}
}
private static TripleDESCryptoServiceProvider TDESP()
{
TripleDESCryptoServiceProvider provider = new TripleDESCryptoServiceProvider();
provider.KeySize = 0xc0;
provider.Key = new byte[] {
0xae, 5, 0x39, 0x5d, 0x42, 0x98, 0x42, 0xa4, 0x4e, 0x29, 0x91, 0x70, 0x19, 0x6f, 0xe8, 0x4d,
8, 0x74, 0xb9, 0xb0, 0x70, 0x7c, 0x69, 0x91
};
provider.IV = new byte[] { 0x1b, 0xf6, 0x95, 0xaf, 0x7d, 0xd6, 90, 0x4f };
provider.Mode = CipherMode.CBC;
provider.Padding = PaddingMode.Zeros;
return provider;
}