zoukankan      html  css  js  c++  java
  • DES(Data Encryption Standard)对称加密

     

    DES加密算法

      DES算法为密码体制中的对称密码体制,又被成为美国数据加密标准,是1972年美国IBM公司研制的对称密码体制加密算法。其密钥长度为56位,明文按64位进行分组,将分组后的明文组和56位的密钥按位替代或交换的方法形成密文组的加密方法。
      DES加密算法特点:分组比较短、密钥太短、密码生命周期短、运算速度较慢。
      DES工作的基本原理是,其入口参数有三个:key、data、mode。 key为加密解密使用的密钥,data为加密解密的数据,mode为其工作模式。当模式为加密模式时,明文按照64位进行分组,形成明文组,key用于对数据加密,当模式为解密模式时,key用于对数据解密。实际运用中,密钥只用到了64位中的56位,这样才具有高的安全性。
      DES( Data Encryption Standard)算法,于1977年得到美国政府的正式许可,是一种用56位密钥来加密64位数据的方法。虽然56位密钥的DES算法已经风光不在,而且常有用Des加密的明文被破译的报道,但是了解一下昔日美国的标准加密算法总是有益的,而且目前DES算法得到了广泛的应用,在某些场合,仍然发挥着余热。

    http://baike.baidu.com/view/1685835.htm

     MSDN示例:

    代码
    private static void EncryptData(String inName, String outName, byte[] desKey, byte[] desIV)
    {
    //Create the file streams to handle the input and output files.
    FileStream fin = new FileStream(inName, FileMode.Open, FileAccess.Read);
    FileStream fout
    = new FileStream(outName, FileMode.OpenOrCreate, FileAccess.Write);
    fout.SetLength(
    0);

    //Create variables to help with read and write.
    byte[] bin = new byte[100]; //This is intermediate storage for the encryption.
    long rdlen = 0; //This is the total number of bytes written.
    long totlen = fin.Length; //This is the total length of the input file.
    int len; //This is the number of bytes to be written at a time.

    DES des
    = new DESCryptoServiceProvider();
    CryptoStream encStream
    = new CryptoStream(fout, des.CreateEncryptor(desKey, desIV), CryptoStreamMode.Write);

    Console.WriteLine(
    "Encrypting...");

    //Read from the input file, then encrypt and write to the output file.
    while(rdlen < totlen)
    {
    len
    = fin.Read(bin, 0, 100);
    encStream.Write(bin,
    0, len);
    rdlen
    = rdlen + len;
    Console.WriteLine(
    "{0} bytes processed", rdlen);
    }

    encStream.Close();
    fout.Close();
    fin.Close();
    }

  • 相关阅读:
    作业9
    第八次作业特征选择
    大数据应用技术课程实践--选题与实践方案
    机器学习——15 手写数字识别-小数据集
    机器学习——14 深度学习-卷积
    机器学习——13-垃圾邮件分类2
    机器学习——12.朴素贝叶斯-垃圾邮件分类
    机器学习——11.分类与监督学习,朴素贝叶斯分类算法
    机器学习——09、主成分分析
    机器学习——08、特征选择
  • 原文地址:https://www.cnblogs.com/wucg/p/1708817.html
Copyright © 2011-2022 走看看