C# DES对称加密解密
/// <summary>
/// 加密
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
private string Encryption(string str)
{
string psw;
string key = "tracymac";
using (DESCryptoServiceProvider des = new DESCryptoServiceProvider())
{
byte[] inputByteArray = Encoding.UTF8.GetBytes(str);
des.Key = ASCIIEncoding.ASCII.GetBytes(key);
des.IV = ASCIIEncoding.ASCII.GetBytes(key);
System.IO.MemoryStream ms = new System.IO.MemoryStream();
using (CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write))
{
cs.Write(inputByteArray, , inputByteArray.Length);
cs.FlushFinalBlock();
cs.Close();
}
psw = Convert.ToBase64String(ms.ToArray());
ms.Close();
}
return psw;
} /// <summary>
/// 解密
/// </summary>
/// <param name="psw"></param>
/// <returns></returns>
private string Decode(string psw)
{
string str;
string key = "tracymac";
using (DESCryptoServiceProvider des = new DESCryptoServiceProvider())
{
byte[] inputByteArray = Convert.FromBase64String(psw);
des.Key = ASCIIEncoding.ASCII.GetBytes(key);
des.IV = ASCIIEncoding.ASCII.GetBytes(key);
System.IO.MemoryStream ms = new System.IO.MemoryStream();
using (CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write))
{
cs.Write(inputByteArray, , inputByteArray.Length);
cs.FlushFinalBlock();
cs.Close();
}
str = Encoding.UTF8.GetString(ms.ToArray());
ms.Close();
}
return str;
}
更多个人工作中的项目请访问我的个人网站:www.88gis.cn
C# DES对称加密解密的更多相关文章
- pyDes 实现 Python 版的 DES 对称加密/解密--转
https://my.oschina.net/leejun2005/blog/586451 手头有个 Java 版的 DES 加密/解密程序,最近想着将其 Python 重构下,方便后续脚本解析,捣鼓 ...
- Asp.Net Core 2.0 项目实战(7)MD5加密、AES&DES对称加解密
本文目录 1. 摘要 2. MD5加密封装 3. AES的加密.解密 4. DES加密/解密 5. 总结 1. 摘要 C#中常用的一些加密和解密方案,如:md5加密.RSA加密与解密和DES加密等, ...
- Java和.NET使用DES对称加密的区别
Java和.NET的系统类库里都有封装DES对称加密的实现方式,但是对外暴露的接口却各不相同,甚至有时会让自己难以解决其中的问题,比如Java加密后的结果在.NET中解密不出来等,由于最近项目有跨Ja ...
- PHP使用DES进行加密解密
DES是一种对称加密算法,也就是通过密文和合法的密钥能够将明文还原出来,在程序开发过程中有些 接口可能需要获取原始数据,而发送的数据又比较敏感(比如用户的密码等信息),这时可以选择DES加密算法,DE ...
- DESEncrypt对称加密解密
分享一个很好用的DESEncrypt对称加密解密的类 using System; using System.Security.Cryptography; using System.Text; usin ...
- php des 对称加解密类
<?php header("Content-Type: text/html;charset=utf-8"); /** * des 对称加解密 */ class des { p ...
- AES对称加密解密类
import java.io.UnsupportedEncodingException; import javax.crypto.Cipher; import javax.crypto.spec.Se ...
- .NET中的DES对称加密
DES是一种对称加密(Data Encryption Standard)算法,于1977年得到美国政府的正式许可,是一种用56位密钥来加密64位数据的方法.一般密码长度为8个字节,其中56位加密密钥, ...
- python AES 双向对称加密解密
高级加密标准(Advanced Encryption Standard,AES),在密码学中又称Rijndael加密法,是美国联邦政府采用的一种区块加密标准.这个标准用来替代原先的DES,已经被多方分 ...
随机推荐
- 老男孩python第六期
01 python s6 day7 上节回顾02 python s6 day7 SNMP使用03 python s6 day7 大型监控架构讲解04 python s6 day7 Redis使用05 ...
- HDU 5735 Born Slippy(拆值DP+位运算)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5735 [题目大意] 给出一棵树,树上每个节点都有一个权值w,w不超过216,树的根为1,从一个点往 ...
- Oracle 生成指定范围内随机日期
Oracle生成一个指定范围内的随机日期 /* 年1月1日)的整数偏移量来保存(即把日期保存为一个数字); * 因此可通过寻找‘指定日期’与‘关键日期’相对应的整数偏移量,再加一个指定范围内的随机整数 ...
- [ javascript ] 司徒正美的fadeOut-fadeIn效果!
首先感谢司徒正美的文章! 在司徒大神的博客看到一个简单的渐入渐出的效果.全然採用js实现. 例如以下: <!doctype html> <html dir="ltr&quo ...
- Android studio 开发在真机测试
真机测试 首先按照这设置android studio: http://jingyan.baidu.com/article/fea4511a75d627f7ba912540.html 2.打开and ...
- CSS learnning...
"Whenever this property changes, apply that change slowly." The property transition: width ...
- C#多线程及GDI(Day 23)
又来到了总结知识的时间了,今天又学了一些新的知识,是多线程和GDI的一些运用. 理论: 在学习多线程之前,首先要了解一下什么是进程? 进程:(关键字Process)进程是一个具有一定独立功能的程 ...
- org.apache.tomcat.util.bcel.classfile.ClassFormatException: null is not a Java .class file
org.apache.tomcat.util.bcel.classfile.ClassFormatException: null is not a Java .class file 在$TOMCA ...
- Cocos2d-x基础篇C++
1.C++类和对象 类的公有成员可以使用成员访问运算符(.)访问. (::)是范围解析运算符.调用成员函数是在对象上使用(.)运算符. 2.C++继承(C++中父类称为基类,子类称为派生类) clas ...
- DevOps探索
devops最近随着docker的升温而被越来越多的人所吸引!最近因项目所需投身到devops的项目当中,经过初步的实践搞出一套 paas平台的devops,这个平台现在还需要检验! 作为一个dev, ...