没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
//加密解密
public class GF_Encrypt
{
/// <summary>
/// DES加密
/// </summary>
/// <param name="pToEncrypt">加密字符串</param>
/// <param name="sKey">密钥</param>
/// <returns></returns>
public static string string_Encrypt(string pToEncrypt, string sKey)
{
if (pToEncrypt == "") return "";
if (sKey.Length < 8) sKey = sKey + "xuE29xWp";
if (sKey.Length > 8) sKey = sKey.Substring(0, 8);
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
//把字符串放到byte数组中
//原来使用的UTF8编码,我改成Unicode编码了,不行
byte[] inputByteArray = Encoding.Default.GetBytes(pToEncrypt);
//建立加密对象的密钥和偏移量
//原文使用ASCIIEncoding.ASCII方法的GetBytes方法
//使得输入密码必须输入英文文本
des.Key = ASCIIEncoding.Default.GetBytes(sKey);
des.IV = ASCIIEncoding.Default.GetBytes(sKey);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write);
//Write the byte array into the crypto stream
//(It will end up in the memory stream)
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
//Get the data back from the memory stream, and into a string
public class GF_Encrypt
{
/// <summary>
/// DES加密
/// </summary>
/// <param name="pToEncrypt">加密字符串</param>
/// <param name="sKey">密钥</param>
/// <returns></returns>
public static string string_Encrypt(string pToEncrypt, string sKey)
{
if (pToEncrypt == "") return "";
if (sKey.Length < 8) sKey = sKey + "xuE29xWp";
if (sKey.Length > 8) sKey = sKey.Substring(0, 8);
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
//把字符串放到byte数组中
//原来使用的UTF8编码,我改成Unicode编码了,不行
byte[] inputByteArray = Encoding.Default.GetBytes(pToEncrypt);
//建立加密对象的密钥和偏移量
//原文使用ASCIIEncoding.ASCII方法的GetBytes方法
//使得输入密码必须输入英文文本
des.Key = ASCIIEncoding.Default.GetBytes(sKey);
des.IV = ASCIIEncoding.Default.GetBytes(sKey);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write);
//Write the byte array into the crypto stream
//(It will end up in the memory stream)
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
//Get the data back from the memory stream, and into a string
StringBuilder ret = new StringBuilder();
foreach (byte b in ms.ToArray())
{
//Format as hex
ret.AppendFormat("{0:X2}", b);
}
ret.ToString();
return ret.ToString();
}
/// <summary>
/// DES解密
/// </summary>
/// <param name="pToDecrypt">解密字符串</param>
/// <param name="sKey">解密密钥</param>
/// <param name="outstr">返回值</param>
/// <returns></returns>
public static bool string_Decrypt(string pToDecrypt, string sKey, out string outstr)
{
if (pToDecrypt == "")
{
outstr = "";
return true;
};
if (sKey.Length < 8) sKey = sKey + "xuE29xWp";
if (sKey.Length > 8) sKey = sKey.Substring(0, 8);
try
{
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
//Put the input string into the byte array
foreach (byte b in ms.ToArray())
{
//Format as hex
ret.AppendFormat("{0:X2}", b);
}
ret.ToString();
return ret.ToString();
}
/// <summary>
/// DES解密
/// </summary>
/// <param name="pToDecrypt">解密字符串</param>
/// <param name="sKey">解密密钥</param>
/// <param name="outstr">返回值</param>
/// <returns></returns>
public static bool string_Decrypt(string pToDecrypt, string sKey, out string outstr)
{
if (pToDecrypt == "")
{
outstr = "";
return true;
};
if (sKey.Length < 8) sKey = sKey + "xuE29xWp";
if (sKey.Length > 8) sKey = sKey.Substring(0, 8);
try
{
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
//Put the input string into the byte array
剩余7页未读,继续阅读
资源评论
guang_hui_yang
- 粉丝: 10
- 资源: 54
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功