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对称性加密的更多相关文章

  1. DES对称加密

    DES是对称性加密里面常见一种,全称为Data Encryption Standard,即数据加密标准,是一种使用密钥加密的块算法.密钥长度是64位(bit),超过位数密钥被忽略.所谓对称性加密,加密 ...

  2. .NET和JAVA同等加密方法,MD5和DES对称加密记录

    C#版: using System; using System.Security.Cryptography; using System.Text; namespace ConsoleApplicati ...

  3. Java和.NET使用DES对称加密的区别

    Java和.NET的系统类库里都有封装DES对称加密的实现方式,但是对外暴露的接口却各不相同,甚至有时会让自己难以解决其中的问题,比如Java加密后的结果在.NET中解密不出来等,由于最近项目有跨Ja ...

  4. 基于DES算法加密的防撞库密码系统项目总结

    项目内容:基于DES算法加密的防撞库密码系统 小组名:zqhzkzkj 目标:1.对用户输入的8位字符进行DES加密,要求用户输入8位密钥 2.对于不同的网站,不同的用户名生成不同的密码 小组成员:周 ...

  5. 使用openssl库实现des,3des加密

    原文地址: 使用openssl库实现des,3des加密 主要是调整了一下格式,以及一些变量的类型,以解决在VC2008下无法编译通过的问题. #include <stdio.h> #in ...

  6. PHP使用DES进行加密解密

    DES是一种对称加密算法,也就是通过密文和合法的密钥能够将明文还原出来,在程序开发过程中有些 接口可能需要获取原始数据,而发送的数据又比较敏感(比如用户的密码等信息),这时可以选择DES加密算法,DE ...

  7. DES的加密与解密算法(Python实现)

    DES的加密与解密算法(Python实现) 密码学实验:实现了DES的简单的加密和解密算法,DES算法的相关资料网上很多,这里不再赘述,仅仅贴出源代码给大家分享,源码中包含很多汉字注释,相信大家都是可 ...

  8. NET实现RSA AES DES 字符串 加密解密以及SHA1 MD5加密

    本文列举了    数据加密算法(Data Encryption Algorithm,DEA) 密码学中的高级加密标准(Advanced EncryptionStandard,AES)RSA公钥加密算法 ...

  9. .NET中的DES对称加密

    DES是一种对称加密(Data Encryption Standard)算法,于1977年得到美国政府的正式许可,是一种用56位密钥来加密64位数据的方法.一般密码长度为8个字节,其中56位加密密钥, ...

随机推荐

  1. 转载《SimpleAdapter的参数说明》

    SimpleAdapter的参数说明 第一个参数 表示访问整个android应用程序接口,基本上所有的组件都需要 第二个参数表示生成一个Map(String ,Object)列表选项 第三个参数表示界 ...

  2. 拓展Yii Framework(易框架)

    1.拓展yii 此文针对Yii1.1.15而写,请注意甄别你的Yii Framework 版本. 拓展yii是开发期间常见的代码处理方式.例如,你写一个新的controller(业务控制器),你通过继 ...

  3. KMP算法的详细解释及实现

    这是我自己学习算法时有关KMP的学习笔记,代码注释的十分的详细,分享给大家,希望对大家有所帮助 在介绍KMP算法之前, 先来介绍一下朴素模式匹配算法: 朴素模式匹配算法: 假设要从主串S=”goodg ...

  4. code forces 383 Arpa's loud Owf and Mehrdad's evil plan(有向图最小环)

    Arpa's loud Owf and Mehrdad's evil plan time limit per test 1 second memory limit per test 256 megab ...

  5. Java学习

    第一个java程序: 用记事本创建一个文件名为HelloWorld.java文件,我的目录为D:\My Documents\Java-workspace\Test\HelloWorld.java. 打 ...

  6. Makefile经典教程(掌握这些足够)

    makefile很重要 什么是makefile?或许很多Winodws的程序员都不知道这个东西,因为那些Windows的IDE都为你做了这个工作,但我觉得要作一个好的和professional的程序员 ...

  7. docker-centos 7.2

    1.安装准备 预防volumes项出现Permission denied setenforce 0 #关闭selinux防火墙,临时关闭.永久关闭需改/etc/selinux/config文件,将SE ...

  8. Character类的2个定义大小写方法以及charAt(int index)方法

    API文档charAt(int index)是这样定义的: charAt(char index):Returns the char value at the specified index.在指定的索 ...

  9. WPF中的image控件的Source赋值

    WPF中的Image控件Source的设置 1.XAML中 简单的方式(Source="haha.png"); image控件的Source设置为相对路径后(Source=&quo ...

  10. GDI+ 操作TIFF ccitt t.6 压缩

    Bitmap Bi=new Bitmap("C:\img.tif"); SaveFileDialog sfdlg = new SaveFileDialog(); sfdlg.Fil ...