DES对称性加密
using System;
using System.Security.Principal;
using System.Security.Permissions;
using System.Security.Cryptography; namespace Demo
{
class MainClass
{
/// <summary>
/// DESCryptoServiceProvider
/// </summary>
public static void DESCryptoDemo ()
{
string message = "This message is security!";
string strEncryp, strDecryp; DESCryptoServiceProvider des = new DESCryptoServiceProvider ();
System.Text.Encoding encoding = new System.Text.UTF8Encoding (); byte[] key = encoding.GetBytes ("1a345689");
byte[] iv = { , , , , , , , };
ICryptoTransform encryptor = des.CreateEncryptor (key, iv);
ICryptoTransform decryptor = des.CreateDecryptor (key, iv);
//all above 4 lines can be TiHuan as below
des.GenerateKey ();
des.GenerateIV ();
encryptor = des.CreateEncryptor ();
decryptor = des.CreateDecryptor ();
{
byte[] byteMessage = encoding.GetBytes (message);
byte[] byteEncrypto = encryptor.TransformFinalBlock (byteMessage, , byteMessage.Length);
strEncryp = Convert.ToBase64String (byteEncrypto);
}
{
byte[] byteEncryto2 = Convert.FromBase64String (strEncryp);
byte[] byteDecrypto = decryptor.TransformFinalBlock (byteEncryto2, , byteEncryto2.Length);
strDecryp = encoding.GetString (byteDecrypto);
}
Console.WriteLine ("Message:" + message);
Console.WriteLine ("Encrypted:" + strEncryp);
Console.WriteLine ("Decrypted:" + strDecryp);
Console.ReadKey ();
} public static void Invoke (Action action)
{
try {
action ();
} catch (Exception ex) {
Console.WriteLine (ex.Message);
}
} public static void Main (string[] args)
{
DESCryptoDemo ();
Invoke (() => TestMethod1 ());
Invoke (() => TestMethod2 ());
Invoke (() => TestMethod3 ());
Console.ReadKey ();
} [PrincipalPermission (SecurityAction.Demand, Name = "Administrator")]
public static void TestMethod1 ()
{
Console.WriteLine ("TestMethod1 successfully Executed!");
} [PrincipalPermission (SecurityAction.Demand, Role = "Administrators")]
public static void TestMethod2 ()
{
Console.WriteLine ("TestMethod2 successfully Executed!");
} [PrincipalPermission (SecurityAction.Demand, Role = "Guests")]
public static void TestMethod3 ()
{
Console.WriteLine ("TestMethod3 successfully Executed!");
}
}
}
DES对称性加密的更多相关文章
- DES对称加密
DES是对称性加密里面常见一种,全称为Data Encryption Standard,即数据加密标准,是一种使用密钥加密的块算法.密钥长度是64位(bit),超过位数密钥被忽略.所谓对称性加密,加密 ...
- .NET和JAVA同等加密方法,MD5和DES对称加密记录
C#版: using System; using System.Security.Cryptography; using System.Text; namespace ConsoleApplicati ...
- Java和.NET使用DES对称加密的区别
Java和.NET的系统类库里都有封装DES对称加密的实现方式,但是对外暴露的接口却各不相同,甚至有时会让自己难以解决其中的问题,比如Java加密后的结果在.NET中解密不出来等,由于最近项目有跨Ja ...
- 基于DES算法加密的防撞库密码系统项目总结
项目内容:基于DES算法加密的防撞库密码系统 小组名:zqhzkzkj 目标:1.对用户输入的8位字符进行DES加密,要求用户输入8位密钥 2.对于不同的网站,不同的用户名生成不同的密码 小组成员:周 ...
- 使用openssl库实现des,3des加密
原文地址: 使用openssl库实现des,3des加密 主要是调整了一下格式,以及一些变量的类型,以解决在VC2008下无法编译通过的问题. #include <stdio.h> #in ...
- PHP使用DES进行加密解密
DES是一种对称加密算法,也就是通过密文和合法的密钥能够将明文还原出来,在程序开发过程中有些 接口可能需要获取原始数据,而发送的数据又比较敏感(比如用户的密码等信息),这时可以选择DES加密算法,DE ...
- DES的加密与解密算法(Python实现)
DES的加密与解密算法(Python实现) 密码学实验:实现了DES的简单的加密和解密算法,DES算法的相关资料网上很多,这里不再赘述,仅仅贴出源代码给大家分享,源码中包含很多汉字注释,相信大家都是可 ...
- NET实现RSA AES DES 字符串 加密解密以及SHA1 MD5加密
本文列举了 数据加密算法(Data Encryption Algorithm,DEA) 密码学中的高级加密标准(Advanced EncryptionStandard,AES)RSA公钥加密算法 ...
- .NET中的DES对称加密
DES是一种对称加密(Data Encryption Standard)算法,于1977年得到美国政府的正式许可,是一种用56位密钥来加密64位数据的方法.一般密码长度为8个字节,其中56位加密密钥, ...
随机推荐
- 缓存,socket乱码等
在服务端默认的编码情况下,JAVA的SOCKET接收需要GBK编码,而C#的接收需要UTF-8编码
- python built-in zip()
zip([iterable, ...]) 返回一个list ,list里的元素是元组tuple.第i个元组内的元素是所有iteralbe中第i个元素组成的. 当所有的iterable拥有同样的长度的时 ...
- QT QString 很全的使用 (转)
QString, QByteArray, 和 QVariant这三个类和容器有许多相同之处,并且在一些情况下可以被当作特殊的容器. 同样,像容器,这些类使用隐式共享来优化内存和速度. 我们将从QStr ...
- PCB的过孔
在走多层板时,经常需要打过孔,那么过孔是怎么分类的呢?且往下看. (1)通孔:这种孔穿过整个线路板,可以用于内部互连或者作为元件的安装定位孔(用于连接层:生成钻孔文件,在PCB上打孔并在孔内电镀:通常 ...
- httpie工具介绍
github:https://github.com/jkbrzt/httpie 一:HTTPie用途 HTTPie (读aych-tee-tee-pie)是一个 HTTP 的命令行客户端.其目标是让 ...
- oracle单机改变归档路径
oracle 归档日志文件路径设置 1. 查看LOG_ARCHIVE_DEST 与 ( LOG_ARCHIVE_DEST_n 或 DB_RECOVERY_FILE_DEST )参数情况注意( LO ...
- Oracle 11g r2 安装
Help Center:http://docs.oracle.com/cd/E11882_01/install.112/e24326/toc.htm#i1011296 前提:linux需要安装图形化介 ...
- os and shutil
# os 模块 os.sep 可以取代操作系统特定的路径分隔符.windows下为 '\\'os.name 字符串指示你正在使用的平台.比如对于Windows,它是'nt',而对于Linux/Unix ...
- C#将exe运行程序嵌入到自己的winform窗体中
以下例子是将Word打开,然后将它嵌入到winform窗体中,效果如下图:C将exe运行程序嵌入到自己的winform窗体中 - kingmax_res - iSport注意:该方法只适用于com的e ...
- (error) MISCONF Redis is configured to save RDB snapshots, but is currently not able to persist on disk. Commands that may modify the data set are disabled. Please check Redis logs for details about t
运行redis过程中,突然报错如下: (error) MISCONF Redis is configured to save RDB snapshots, but is currently not a ...