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. c语言数据结构之 堆排序

    算法:先生成随机数,赋值到数组,将数组第一个元素a[0]设置为哨兵,函数调用数组和随机数个数n,再设定n/2的根结点与孩子结点进行比较操作,若右孩子存在,则选出三个数里最小的数赋值给根节点,如果右孩子 ...

  2. Mongodb和Hive详细对比

    本文主要用于分析在大数据场景下Mongodb和Hive的优缺点: 支持的数据类型 支持的查询 支持的数据量 性能优化手段

  3. Sequential List

    Sequential ListSequential list storage structure:#define LIST_INIT_SIZE 20 #define LIST_INCREASE 10t ...

  4. java多线程基础

    多线程基础 读书练习照猫画虎 package Threadtest; import java.util.Date; import java.util.concurrent.ArrayBlockingQ ...

  5. app打包(同步发生冲突)

    1:打包步骤: 1:桌面建立一个文件夹,名字叫keystore 2:点击build下面的 ,如下:     3:会出现如下界面: 4:下一步: 5:如果有keystore,请点击 choose exi ...

  6. redis主从配置

    首先安装redis 我的redis安装在/app/redis/文件夹下 第二步,写两个redis实例的配置文件,一主一从.我的设计如下,6379端口为主,6380端口为从. 6379:redis_ma ...

  7. Spring+SpringMVC+Mybatis大整合(SpringMVC采用REST风格、mybatis采用Mapper代理)

    整体目录结构: 其中包下全部是采用mybatis自动生成工具生成. mybatis自动生成文件 <?xml version="1.0" encoding="UTF- ...

  8. jQuery下通过$.browser来判断浏览器

    使用方法: $.browser.['浏览器关键字'] 代码如下: $(function() { if($.browser.msie) { alert("this is msie") ...

  9. 利用web工具splinter模拟登陆做自动签到

    首先,我需要的工具和组件有: Chrome浏览器 浏览器驱动ChromeDriver Python 3.5 Web应用测试工具Splinter 代码部分: from splinter import B ...

  10. IDEA Generating project in Batch mode

    Idea 设置 -DarchetypeCatalog=internal 然后再执行 : Archetype repository not defined. Using the one from [or ...