using System;
using System.Security;
using System.Security.Cryptography;
using System.IO;
namespace cry
{
/// <summary>
/// Cryop 的摘要说明。
/// </summary>
public class Cryop
{
//Keys与IV的长度相等
private static Byte[] Keys = System.Text.Encoding.Unicode.GetBytes("天天向上");
private static Byte[] IV = new Byte[]{0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF};
/// <summary>
/// 加密
/// </summary>
public static Byte[] Enc(String test)
{
System.Security.Cryptography.RC2CryptoServiceProvider rc2 = new RC2CryptoServiceProvider();
MemoryStream msStream = new MemoryStream();
byte[] toEncrypt;
try
{
ICryptoTransform encrypt = rc2.CreateEncryptor(Keys,IV);
CryptoStream csStream = new CryptoStream(msStream,encrypt,CryptoStreamMode.Write);
toEncrypt = System.Text.Encoding.Unicode.GetBytes(test);
csStream.Write(toEncrypt,0,toEncrypt.Length);
csStream.FlushFinalBlock();
}
catch(Exception ex)
{
throw new Exception(ex.Message,ex);
}
return msStream.ToArray();
}
/// <summary>
/// 解密
/// </summary>
public static String Dec(Byte[] enc)
{
System.Security.Cryptography.RC2CryptoServiceProvider rc2 = new RC2CryptoServiceProvider();
try
{
ICryptoTransform decrypt = rc2.CreateDecryptor(Keys,IV);
MemoryStream msDec = new MemoryStream(enc);
CryptoStream csDec = new CryptoStream(msDec,decrypt,CryptoStreamMode.Read);
byte[] fromEncpty = new Byte[enc.Length];
csDec.Read(fromEncpty,0,fromEncpty.Length);
return System.Text.Encoding.Unicode.GetString(fromEncpty);
}
catch(Exception ex)
{
throw new Exception(ex.Message,ex);
}
}
}
}
using System.Security;
using System.Security.Cryptography;
using System.IO;
namespace cry
{
/// <summary>
/// Cryop 的摘要说明。
/// </summary>
public class Cryop
{
//Keys与IV的长度相等
private static Byte[] Keys = System.Text.Encoding.Unicode.GetBytes("天天向上");
private static Byte[] IV = new Byte[]{0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF};
/// <summary>
/// 加密
/// </summary>
public static Byte[] Enc(String test)
{
System.Security.Cryptography.RC2CryptoServiceProvider rc2 = new RC2CryptoServiceProvider();
MemoryStream msStream = new MemoryStream();
byte[] toEncrypt;
try
{
ICryptoTransform encrypt = rc2.CreateEncryptor(Keys,IV);
CryptoStream csStream = new CryptoStream(msStream,encrypt,CryptoStreamMode.Write);
toEncrypt = System.Text.Encoding.Unicode.GetBytes(test);
csStream.Write(toEncrypt,0,toEncrypt.Length);
csStream.FlushFinalBlock();
}
catch(Exception ex)
{
throw new Exception(ex.Message,ex);
}
return msStream.ToArray();
}
/// <summary>
/// 解密
/// </summary>
public static String Dec(Byte[] enc)
{
System.Security.Cryptography.RC2CryptoServiceProvider rc2 = new RC2CryptoServiceProvider();
try
{
ICryptoTransform decrypt = rc2.CreateDecryptor(Keys,IV);
MemoryStream msDec = new MemoryStream(enc);
CryptoStream csDec = new CryptoStream(msDec,decrypt,CryptoStreamMode.Read);
byte[] fromEncpty = new Byte[enc.Length];
csDec.Read(fromEncpty,0,fromEncpty.Length);
return System.Text.Encoding.Unicode.GetString(fromEncpty);
}
catch(Exception ex)
{
throw new Exception(ex.Message,ex);
}
}
}
}