• DES解密,ECB模式,PKCS7填充标准


    最近工作中用到了des解密,之前没接触过,花了点时间去研究了一下,des算是比较基础的加密方式了,这边主要讲的是ECB模式,ECB模式作为一种基本工作模式,具有操作简单,易于实现的特点。同时由于其分组的独立性,利于实现并行处理,并且能很好地防止误差传播。个人觉得ECB比较适用于密钥保护。代码如下:

    按 Ctrl+C 复制代码

    public class DesHelper
        {
            private static String _ConstValue = "12345678";
            public static String Decipher(String Str, bool IncludeLocalInfo)
            {
                if (null == Str || 0 == Str.Length) return "";
                try
                {
                    SymmetricAlgorithm sa = new DESCryptoServiceProvider();
                    String _Key = _ConstValue;
                    sa.Key = Encoding.UTF8.GetBytes(_Key);
                    sa.IV = Encoding.UTF8.GetBytes(_ConstValue);
                    sa.Mode = System.Security.Cryptography.CipherMode.ECB;
                    sa.Padding = PaddingMode.PKCS7;
                     ICryptoTransform ct = sa.CreateDecryptor();
                    byte[] byt = Convert.FromBase64String(Str);
                    MemoryStream ms = new MemoryStream();
                    CryptoStream cs = new CryptoStream(ms, ct, CryptoStreamMode.Write);
                    cs.Write(byt, 0, byt.Length);
                    cs.FlushFinalBlock();
                    cs.Close();
                    return Encoding.UTF8.GetString(ms.ToArray());
                }
                catch(Exception e) {

                }
                return "";
            }
        }

    按 Ctrl+C 复制代码

    没错,代码就是如此简单

  • 相关阅读:
    react脚手架和JSX
    promise
    防抖和节流
    call/apply/bind 用法
    js this指向
    vue单页面应用刷新网页后vuex的state数据丢失的解决方案
    Echarts基础
    继承
    原型链
    vue项目中使用生成动态二维码
  • 原文地址:https://www.cnblogs.com/zhujunfie/p/7493907.html
Copyright © 2020-2023  润新知