zoukankan      html  css  js  c++  java
  • DES加密

     string key = "hdyxsjtd";//密匙8个字符
            //加密
            public string JiaMi(string sourceString)
            {
                byte[] keyBytes = Encoding.UTF8.GetBytes(key);
                byte[] keyIV = keyBytes;
                byte[] inputByteArray = Encoding.UTF8.GetBytes(sourceString);
                DESCryptoServiceProvider desProvider = new DESCryptoServiceProvider();
                MemoryStream memStream = new MemoryStream();
                CryptoStream crypStream = new CryptoStream(memStream, desProvider.CreateEncryptor(keyBytes, keyIV), CryptoStreamMode.Write);
                crypStream.Write(inputByteArray, 0, inputByteArray.Length);
                crypStream.FlushFinalBlock();
                return Convert.ToBase64String(memStream.ToArray());
            }

            //解密的函数
            public string JieMi(string encryptString)
            {
                byte[] keyBytes = Encoding.UTF8.GetBytes(key);
                byte[] keyIV = keyBytes;
                byte[] inputByteArray = Convert.FromBase64String(encryptString);
                DESCryptoServiceProvider desProvider = new DESCryptoServiceProvider();
                MemoryStream memStream = new MemoryStream();
                CryptoStream crypStream = new CryptoStream(memStream, desProvider.CreateDecryptor(keyBytes, keyIV), CryptoStreamMode.Write);
                crypStream.Write(inputByteArray, 0, inputByteArray.Length);
                crypStream.FlushFinalBlock();
                return Encoding.UTF8.GetString(memStream.ToArray());
            }

  • 相关阅读:
    D. Renting Bikes 二分
    Maximum Absurdity DP + 数学
    模拟 H
    Secrets 数论
    A. Knight Tournament SET的应用
    B. Xenia and Hamming Codeforces 256B GCD,LCM处理字符串
    Alternate Task UVA11728 暴力枚举
    GCD Extreme (II) 欧拉函数的应用
    Bit Magic HDU 4421 2-Sat
    Encoding http://acm.hdu.edu.cn/showproblem.php?pid=1020
  • 原文地址:https://www.cnblogs.com/Iyce/p/2738656.html
Copyright © 2011-2022 走看看