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注册。

  • 相关阅读:
    如何让两个线程同时运行
    测试人员绩效评价方法
    转载:浅谈实施软件测试风险分析
    项目测试流程总结
    HttpClient使用小结
    浅谈分布式事务原理及其应用场景
    (.NET高级课程笔记)Lambd、Linq总结
    (.NET高级课程笔记)反射总结
    (.NET高级课程笔记)泛型总结
    Lambda表达式详解(例子详解)(转自:http://blog.csdn.net/damon316/article/details/51734661)
  • 原文地址:https://www.cnblogs.com/zjypp/p/2319498.html
Copyright © 2011-2022 走看看