• C# PKCS7加密解密


    //加密字符串
        public string Encryption(string toE)
        {
            //加密和解密必须采用相同的key,具体自己填写,但是必须为32位
            byte[] keyArray = UTF8Encoding.UTF8.GetBytes("12345678123456781234567812345678");
            RijndaelManaged rijndaelManaged = new RijndaelManaged();
            rijndaelManaged.Key = keyArray;
            rijndaelManaged.Mode = CipherMode.ECB;
            rijndaelManaged.Padding = PaddingMode.PKCS7;
            ICryptoTransform icryptoTransform = rijndaelManaged.CreateEncryptor();
    
            byte[] toEncryptArray = UTF8Encoding.UTF8.GetBytes(toE);
            byte[] resultArray = icryptoTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
    
            return Convert.ToBase64String( resultArray, 0, resultArray.Length);
        }
    
        //解密字符串
        public string Decryption(string toD)
        { 
            //加密和解密必须采用相同的key,具体值自己填,但是必须为32位
            byte[] keyArray = UTF8Encoding.UTF8.GetBytes("12345678123456781234567812345678");
            RijndaelManaged rijndaelManaged = new RijndaelManaged();
            rijndaelManaged.Key = keyArray;
            rijndaelManaged.Mode = CipherMode.ECB;
            rijndaelManaged.Padding = PaddingMode.PKCS7;
            ICryptoTransform cTransform = rijndaelManaged.CreateDecryptor();
    
            byte[] toEncryptArray = Convert.FromBase64String(toD);
            byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
    
            return UTF8Encoding.UTF8.GetString(resultArray);
        }
  • 相关阅读:
    join()方法的使用
    synchronized关键字
    voliatle关键字
    一.线程概述
    NIO demo
    同步阻塞I/O
    Ubuntu16.04.1 安装Nginx
    垃圾收集
    如何从头开始安装 wordpress
    centos 6 安装 gnu c++ 等开发工具
  • 原文地址:https://www.cnblogs.com/Fooo/p/11012812.html
Copyright © 2020-2023  润新知