#region DESEnCode DES加密
//使用这个!!!
public static string DESEnCode(string pToEncrypt, string sKey)
{
//sKey = "NudsxliCwfeqaOKI";
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
byte[] inputByteArray = Encoding.GetEncoding("UTF-8").GetBytes(pToEncrypt);
//建立加密对象的密钥和偏移量
//原文使用ASCIIEncoding.ASCII方法的GetBytes方法
//使得输入密码必须输入英文文本
//des.Mode = CipherMode.ECB;
des.Key = ASCIIEncoding.ASCII.GetBytes(sKey.Substring(0, 8).ToString());
des.IV = ASCIIEncoding.ASCII.GetBytes(sKey.Substring(8, 8).ToString());
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushF
C# DES加密 DES/CSC/PKCS7 秘钥+偏移量+hex输出
最新推荐文章于 2023-12-05 17:02:00 发布