zoukankan      html  css  js  c++  java
  • net des加密解密

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.IO;
    using System.Security.Cryptography;
    using System.Web;

    namespace DES
    {
        class Des2
        {
            const string KEY_64 = "VavicApp";//随便的8个字符串 密钥
            const string IV_64 = "VavicApp";//随便的8个字符串

            public Des2()
            {
     
            }

            public static string Encode(string data)
            {
                byte[] byKey = System.Text.ASCIIEncoding.ASCII.GetBytes(KEY_64);
                byte[] byIV = System.Text.ASCIIEncoding.ASCII.GetBytes(IV_64);

                DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();
                int i = cryptoProvider.KeySize;
                MemoryStream ms = new MemoryStream();
                CryptoStream cst = new CryptoStream(ms, cryptoProvider.CreateEncryptor(byKey, byIV), CryptoStreamMode.Write);

                StreamWriter sw = new StreamWriter(cst);
                sw.Write(data);
                sw.Flush();
                cst.FlushFinalBlock();
                sw.Flush();
                return Convert.ToBase64String(ms.GetBuffer(), 0, (int)ms.Length);

            }

            public static string Decode(string data)
            {
                byte[] byKey = System.Text.ASCIIEncoding.ASCII.GetBytes(KEY_64);
                byte[] byIV = System.Text.ASCIIEncoding.ASCII.GetBytes(IV_64);

                byte[] byEnc;
                try
                {
                    byEnc = Convert.FromBase64String(data);
                }
                catch
                {
                    return null;
                }

                DESCryptoServiceProvider cryptoProvider = new DESCryptoServiceProvider();
                MemoryStream ms = new MemoryStream(byEnc);
                CryptoStream cst = new CryptoStream(ms, cryptoProvider.CreateDecryptor(byKey, byIV), CryptoStreamMode.Read);
                StreamReader sr = new StreamReader(cst);
                return sr.ReadToEnd();
            }


        }
    }

    本文使用Blog_Backup未注册版本导出,请到soft.pt42.com注册。

  • 相关阅读:
    [React Testing] Create a Custom Render Function to Simplify Tests of Redux Components
    [React Testing] Test a Custom React Hook with React’s Act Utility and a Test Component
    Android之Android apk动态加载机制的研究
    Android之设备唯一识别
    ios之调用打电话,发短信,打开网址
    ios之如何读取plist
    android之卸载反馈的功能
    Android之针对webview的缓存
    Android之仿String的对象驻留
    Mac与Mac之中的共享方式
  • 原文地址:https://www.cnblogs.com/zjypp/p/2319498.html
Copyright © 2011-2022 走看看