zoukankan      html  css  js  c++  java
  • AES加密和解密

    //AES加密
    public static byte[] Encrypt(string str)
    {
    string key = " "; //秘钥根据自己的协议自行填写
    if (string.IsNullOrEmpty(str)) return null;
    Byte[] toEncryptArray = strToToHexByte(str);

    RijndaelManaged rm = new RijndaelManaged
    {
    Key = strToToHexByte(key),
    Mode = CipherMode.ECB,           //运算模式
    Padding = PaddingMode.PKCS7   //pkcs7会填充成一个默认32个字节的数组
    };

    ICryptoTransform cTransform = rm.CreateEncryptor();
    Byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
    return resultArray;
    }

     //AES解密

            public static byte[] Decrypt(string str)

            {

                string key = " "; //秘钥根据自己的协议自行填写

                if (string.IsNullOrEmpty(str)) return null;

                Byte[] toEncryptArray = AES.strToToHexByte(str);

                RijndaelManaged rm = new RijndaelManaged

                {

                    Key = AES.strToToHexByte(key),

                    Mode = CipherMode.ECB,   //运算模式

                    Padding = PaddingMode.PKCS7,  //填充类型

                };

                ICryptoTransform cTransform = rm.CreateDecryptor();

                Byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);

                return resultArray;

            }

  • 相关阅读:
    PIC32MZ tutorial -- Core Timer
    PIC32MZ tutorial -- OC Interrupt
    PIC32MZ tutorial -- External Interrupt
    PIC32MZ tutorial -- Watchdog Timer
    PIC32MZ tutorial -- Output Compare
    PIC32MZ tutorial -- Input Capture
    PIC32MZ tutorial -- 32-bit Timer
    log | logstash
    Vxlan学习笔记——原理
    python——字符串格式化
  • 原文地址:https://www.cnblogs.com/fkxx/p/14376374.html
Copyright © 2011-2022 走看看