⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cryptencryptor.cs

📁 这是可以加密&解密字符串
💻 CS
字号:
using System;
using System.IO;
using System.Security.Cryptography;

namespace EncryptDecrypt
{
    /// <summary>
    /// 加密类。
    /// </summary>
    public class CryptEncryptor
    {
        private Stream inputStream;
        private Stream outputStream;
        private CryptoStream cstream = null;

        public CryptEncryptor(Stream inputStream, Stream outputStream)
        {
            this.inputStream = inputStream;
            this.outputStream = outputStream;
        }

        public Stream InputStream
        {
            get { return inputStream; }
            set { inputStream = value; }
        }

        public Stream OutputStream
        {
            get { return outputStream; }
            set { outputStream = value; }
        }

        public void Execute()
        {
            //定义对称算法对象实例和接口
            SymmetricAlgorithm symm = new RijndaelManaged();
            ICryptoTransform transform = symm.CreateEncryptor();
            cstream = new CryptoStream(outputStream, transform, CryptoStreamMode.Write);

            BinaryReader br = new BinaryReader(inputStream);
            //读取源文件到CryptoStream 
            cstream.Write(br.ReadBytes((int)inputStream.Length), 0, (int)inputStream.Length);
            cstream.FlushFinalBlock();
        }

        private void Close()
        {
            if (cstream != null)
            {
                cstream.Close();
                cstream = null;
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -