码迷,mamicode.com
首页 > Windows程序 > 详细

C#NET字符编码加解密的参考代码

时间:2020-03-04 22:31:38      阅读:77      评论:0      收藏:0      [点我收藏+]

标签:using   name   字符编码   encode   net   color   public   col   oar   

 //C#NET字符编码加解密的参考代码我是从老外程序里面拷贝出来的希望对大家有所用
1
public string Encrypt(string name) { 2 byte ivId = GetIVId(name); 3 cipher.IV = GetIV(ivId); 4 var buf = Encoding.UTF8.GetBytes(name); 5 6 using (var ms = new MemoryStream()) { 7 ms.WriteByte(ivId); 8 using (var stream = new CryptoStream(ms, cipher.CreateEncryptor(), CryptoStreamMode.Write)) 9 stream.Write(buf, 0, buf.Length); 10 11 buf = ms.ToArray(); 12 return Base64Encode(buf); 13 } 14 } 15 16 public string Decrypt(string name) { 17 using (var ms = new MemoryStream(Base64Decode(name))) { 18 byte ivId = (byte)ms.ReadByte(); 19 cipher.IV = GetIV(ivId); 20 21 var result = new MemoryStream(); 22 using (var stream = new CryptoStream(ms, cipher.CreateDecryptor(), CryptoStreamMode.Read)) 23 stream.CopyTo(result); 24 25 return Encoding.UTF8.GetString(result.ToArray()); 26 } 27 }

 

C#NET字符编码加解密的参考代码

标签:using   name   字符编码   encode   net   color   public   col   oar   

原文地址:https://www.cnblogs.com/wz2988/p/12416558.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!