打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
加密解密类
public class Encrypt                                                                                                              
{                                                                                                                                 
static string key = "441568140";                                                                                                
static byte[] Keys = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF };                                                        
public Encrypt() {}                                                                                                             
// 加密:                                                                                                                       
public static string EncryptDES(string pass)                                                                                    
{                                                                                                                               
try                                                                                                                           
{                                                                                                                             
byte[] rgbKey = Encoding.UTF8.GetBytes(key.Substring(0, 8));                                                                
byte[] rgbIV = Keys;                                                                                                        
      byte[] inputByteArray = Encoding.UTF8.GetBytes(pass);                                                                       
      DESCryptoServiceProvider provider = new DESCryptoServiceProvider();                                                         
      MemoryStream mStream = new MemoryStream();                                                                                  
      CryptoStream cStream = new CryptoStream(mStream, provider.CreateEncryptor(rgbKey, rgbIV), CryptoStreamMode.Write);          
      cStream.Write(inputByteArray, 0, inputByteArray.Length);                                                                    
      cStream.FlushFinalBlock();                                                                                                  
      return Convert.ToBase64String(mStream.ToArray());                                                                           
    }                                                                                                                             
    catch                                                                                                                         
    {                                                                                                                             
    return pass;                                                                                                                
}                                                                                                                             
}                                                                                                                               
    // 解密:                                                                                                                     
public static string DecryptDES(string pass)                                                                                    
{                                                                                                                               
 try                                                                                                                           
 {                                                                                                                             
   byte[] rgbKey = Encoding.UTF8.GetBytes(key.Substring (0,8));                                                                
   byte[] rgbIV = Keys;                                                                                                        
   byte[] inputByteArray = Convert.FromBase64String(pass);                                                                     
   DESCryptoServiceProvider provider = new DESCryptoServiceProvider();                                                         
   MemoryStream mStream = new MemoryStream();//存储加后的数据                                                                  
   CryptoStream cStream = new CryptoStream(mStream, provider.CreateDecryptor(rgbKey, rgbIV), CryptoStreamMode.Write);          
   cStream.Write(inputByteArray, 0, inputByteArray.Length);                                                                    
   cStream.FlushFinalBlock();                                                                                                  
   return Encoding.UTF8.GetString(mStream.ToArray());                                                                          
 }                                                                                                                             
 catch                                                                                                                         
 {                                                                                                                             
  return pass;                                                                                                                
 }                                                                                                                             
}                                                                                                                               
}                                                                                                                                 


本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
关于DES 过程密钥和密钥分散
C#DES加密
C#里的一些加密解密标准函数示例——DES,SHA1,RSA
C#软件加序列号激活、试用期限
字符串加密与解密
C#一个字符串的加密与解密
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服