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位加密密钥, ...
随机推荐
- service的简单使用
Service的生命周期方法比Activity少一些,只有onCreate, onStart, onDestroy 我们有两种方式启动一个Service,他们对Service生命周期的影响是不一样的. ...
- IOS开发网络数据---- AFNetworking的使用
http网络库是集XML解析,Json解析,网络图片下载,plist解析,数据流请求操作,上传,下载,缓存等网络众多功能于一身的强大的类库.最新版本支持session,xctool单元测试.网络获取数 ...
- js MATH
MATH Math 对象用于执行数学任务. 无需创建它,通过把 Math 作为对象使用就可以调用其所有属性和方法. Math 对象属性 var a=Math.E; //输出2.718281828459 ...
- pyside 为窗口添加图片
有时我们需要添加一些图片到窗口上,下面给一个通过QLable实现的方法. 这里需要注意的是,当你启用多线程时,方法调用的setPixmap,会导致qt报出一个线程安全错误. 因此,让这个绘图工作尽量在 ...
- oracle数据库备份和还原
ip导出方式:exp demo/demo@127.0.0.1:1521/orcl file=f:\f.dmp full=y 备份:exp demo/demo@orcl file=f:\f.dmp f ...
- 未能加载文件或程序集 Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad
没有 microsoft.web.infrastructure.dll 文件. 解决方式: ,第一种:在所发布的项目文件里面的 bin 文件目录下,添加 microsoft.web.infrastru ...
- oracle 职业学习指引
风哥 它是阿里巴巴造出的概念.其本意是,在阿里巴巴的IT架构中,去掉IBM的小型机.Oracle数据库.EMC存储设备,代之以自己在开源软件基础上开发的系统. 思科.IBM.谷歌.高通.英特尔.苹果. ...
- Vigenère密码
来源 NOIP2012复赛 提高组 第一题 描述 16世纪法国外交家Blaise de Vigenère设计了一种多表密码加密算法--Vigenère密码.Vigenère密码的加密解密算法简单易用 ...
- git之.gitignore文件用途
gitignore文件用于忽略无需追踪的文件. 配置文件: $HOME/.config/git/ignore, $GIT_DIR/info/exclude, .gitignore 举例说明: $ gi ...
- Nginx中文域名配置
Nginx虚拟主机上绑定一个带中文域名,比如linuxeye.中国,浏览器不能跳转. why? 因为操作系统的核心都是英文组成,DNS服务器的解析也是由英文代码交换,所以DNS服务器上并不支持直接的中 ...