当前位置:编程学习 > C#/ASP.NET >>

请大家翻译一下这段代码的意思,菜鸟看不懂!

amespace Sky.Decrypt
{
    using System;
    using System.IO;
    using System.Runtime.Serialization;
    using System.Runtime.Serialization.Formatters.Binary;
    using System.Security.Cryptography;
    using System.Text;

    public class Decryption
    {
        private string temporaryFileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "license.dat");

        public string DecryptFile(string path, string key)
        {
            string str = "";
            if (!File.Exists(path))
            {
                throw new Exception("File is not exist.");
            }
            byte[] rgbIV = new byte[] { 0x12, 0x34, 0x56, 120, 0x90, 0xab, 0xcd, 0xef };
            byte[] bytes = Encoding.UTF8.GetBytes(key);
            FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read);
            long length = stream.Length;
            DES des = new DESCryptoServiceProvider();
            CryptoStream stream2 = new CryptoStream(stream, des.CreateDecryptor(bytes, rgbIV), CryptoStreamMode.Read);
            StreamReader reader = new StreamReader(stream2);
            try
            {
                str = reader.ReadToEnd();
            }
            finally
            {
                stream.Close();
            }
            return str;
        }

        public string DecryptString(string data, string key)
        {
            string str = "";
            if ((data == null) || (data == ""))
            {
                throw new Exception("Data is empty.");
            }
            byte[] rgbIV = new byte[] { 0x12, 0x34, 0x56, 120, 0x90, 0xab, 0xcd, 0xef };
            byte[] bytes = Encoding.UTF8.GetBytes(key);
            MemoryStream stream = new MemoryStream();
            DES des = new DESCryptoServiceProvider();
            CryptoStream stream2 = new CryptoStream(stream, des.CreateDecryptor(bytes, rgbIV), CryptoStreamMode.Write);
            try
            {
                byte[] buffer = Convert.FromBase64String(data);
                stream2.Write(buffer, 0, buffer.Length);
                stream2.FlushFinalBlock();
                str = Encoding.UTF8.GetString(stream.ToArray());
            }
            finally
            {
                stream2.Close();
                stream.Close();
            }
            return str;
        }

        private string DeserializeFile(string path)
        {
            string str = "";
            if (!File.Exists(path))
            {
                throw new Exception("File is not exist.");
            }
            IFormatter formatter = new BinaryFormatter();
            FileStream serializationStream = new FileStream(path, FileMode.Open, FileAccess.Read);
            try
            {
                str = (string) formatter.Deserialize(serializationStream);
            }
            finally
            {
                serializationStream.Close();
            }
            return str;
        }

        public string GetString(string path)
        {
            return this.DeserializeFile(path);
        }
    }
}
--------------------编程问答-------------------- 分别是解密文件、解密字符串、反序列化文件等函数

你只管调用这些函数就行了,函数体内部的你不用了解

--------------------编程问答-------------------- 那解密密码是什么呢?能知道解密的密码吗?
--------------------编程问答-------------------- 加密用的是什么密码,解密就用什么密码

解密的前提必须知道加密密码,才能解密,跟函数体代码无关 --------------------编程问答-------------------- 现在不知道加密的密码,所以从这段代码中能看出加密的密码吗?
--------------------编程问答-------------------- 能看出来。。。还需要加密吗? --------------------编程问答--------------------
引用 4 楼  的回复:
现在不知道加密的密码,所以从这段代码中能看出加密的密码吗?

看不出来 --------------------编程问答-------------------- --------------------编程问答-------------------- --------------------编程问答-------------------- --------------------编程问答-------------------- --------------------编程问答-------------------- 能看出来。。。还需要加密吗? --------------------编程问答-------------------- 建议,单步调试,结合 msdn 看
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,