zoukankan      html  css  js  c++  java
  • C# 加密-TripleDES

    TripleDES 属对称加密,对称加密在加密和解密时都使用相同的密钥,速度快。

    TripleDESCryptoServiceProvider 的名称空间是:

    System.Security.Cryptography
    byte[] plaintextBuffer = System.Text.Encoding.UTF8.GetBytes("明文");
    
    //加密
    TripleDESCryptoServiceProvider tripleDES = new TripleDESCryptoServiceProvider();
    ICryptoTransform transform = tripleDES.CreateEncryptor();
    byte[] cipherTextBuffer = transform.TransformFinalBlock(plaintextBuffer, 0, plaintextBuffer.Length);
    lbl.Text = Convert.ToBase64String(cipherTextBuffer) + "<br />";
    transform.Dispose();
    
    //解密
    TripleDESCryptoServiceProvider tripleDES2 = new TripleDESCryptoServiceProvider();
    ICryptoTransform transform2 = tripleDES2.CreateDecryptor(tripleDES.Key, tripleDES.IV);
    byte[] decryption = transform2.TransformFinalBlock(cipherTextBuffer, 0, cipherTextBuffer.Length);
    lbl.Text += System.Text.Encoding.UTF8.GetString(decryption) + "<br />";
    transform2.Dispose();

    解密时,使用加密的 Key 和 IV。

  • 相关阅读:
    C++链式队列基本操作
    C++链栈基本操作
    C++顺序栈基本操作
    C++链表基本操作
    C/C++/JAVA
    C++操作链表
    How Many Maos Does the Guanxi Worth
    Heavy Transportation
    Frogger
    Til the Cows Come Home(Dijkstra)
  • 原文地址:https://www.cnblogs.com/ghfsusan/p/1613570.html
Copyright © 2011-2022 走看看