/**//// <summary>
/// DES算法描述简介:
/// DES是Data Encryption Standard(数据加密标准)的缩写。它是由IBM公司研制的一种加密算法,
/// 美国国家标准局于1977年公布把它作为非机要部门使用的数据加密标准;
/// 它是一个分组加密算法,他以64位为分组对数据加密。
/// 同时DES也是一个对称算法:加密和解密用的是同一个算法。
/// 它的密匙长度是56位(因为每个第8 位都用作奇偶校验),
/// 密匙可以是任意的56位的数,而且可以任意时候改变.
/// </summary>
static class Class1
...{
private static byte[] IV = ...{ 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF };
public static String Encrypt(String Key, String str)
...{
byte[] bKey = Encoding.UTF8.GetBytes(Key.Substring(0, 8));
byte[] bIV = IV;
byte[] bStr = Encoding.UTF8.GetBytes(str);
try
...{
DESCryptoServiceProvider desc = new DESCryptoServiceProvider();
MemoryStream mStream = new MemoryStream();
CryptoStream cStream = new CryptoStream(mStream, desc.CreateEncryptor(bKey, bIV), CryptoStreamMode.Write);
cStream.Write(bStr, 0, bStr.Length);
cStream.FlushFinalBlock();
return Convert.ToBase64String(mStream.ToArray());
}
catch
...{
return string.Empty;
}
}
public static String Decrypt(String Key, String DecryptStr)
...{
try
...{
byte[] bKey = Encoding.UTF8.GetBytes(Key.Substring(0, 8));
byte[] bIV = IV;
byte[] bStr = Convert.FromBase64String(DecryptStr);
DESCryptoServiceProvider desc = new DESCryptoServiceProvider();
MemoryStream mStream = new MemoryStream();
CryptoStream cStream = new CryptoStream(mStream, desc.CreateDecryptor(bKey, bIV), CryptoStreamMode.Write);
cStream.Write(bStr, 0, bStr.Length);
cStream.FlushFinalBlock();
return Encoding.UTF8.GetString(mStream.ToArray());
}
catch
...{
return string.Empty;
}
}
}
/// DES算法描述简介:
/// DES是Data Encryption Standard(数据加密标准)的缩写。它是由IBM公司研制的一种加密算法,
/// 美国国家标准局于1977年公布把它作为非机要部门使用的数据加密标准;
/// 它是一个分组加密算法,他以64位为分组对数据加密。
/// 同时DES也是一个对称算法:加密和解密用的是同一个算法。
/// 它的密匙长度是56位(因为每个第8 位都用作奇偶校验),
/// 密匙可以是任意的56位的数,而且可以任意时候改变.
/// </summary>
static class Class1
...{
private static byte[] IV = ...{ 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF };
public static String Encrypt(String Key, String str)
...{
byte[] bKey = Encoding.UTF8.GetBytes(Key.Substring(0, 8));
byte[] bIV = IV;
byte[] bStr = Encoding.UTF8.GetBytes(str);
try
...{
DESCryptoServiceProvider desc = new DESCryptoServiceProvider();
MemoryStream mStream = new MemoryStream();
CryptoStream cStream = new CryptoStream(mStream, desc.CreateEncryptor(bKey, bIV), CryptoStreamMode.Write);
cStream.Write(bStr, 0, bStr.Length);
cStream.FlushFinalBlock();
return Convert.ToBase64String(mStream.ToArray());
}
catch
...{
return string.Empty;
}
}
public static String Decrypt(String Key, String DecryptStr)
...{
try
...{
byte[] bKey = Encoding.UTF8.GetBytes(Key.Substring(0, 8));
byte[] bIV = IV;
byte[] bStr = Convert.FromBase64String(DecryptStr);
DESCryptoServiceProvider desc = new DESCryptoServiceProvider();
MemoryStream mStream = new MemoryStream();
CryptoStream cStream = new CryptoStream(mStream, desc.CreateDecryptor(bKey, bIV), CryptoStreamMode.Write);
cStream.Write(bStr, 0, bStr.Length);
cStream.FlushFinalBlock();
return Encoding.UTF8.GetString(mStream.ToArray());
}
catch
...{
return string.Empty;
}
}
}