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

📄 cipher.cs

📁 Hide-Delete icon from ToolBar32 for specific process , from command line arguments. TBBUTTON CSha
💻 CS
字号:
using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;

namespace LicenseManage.BaseClasses
{
    class CryptFile
    {
        private const string password = "_;v.]05-31!|+-%xT!^[$\00";
        private const int iterations = 1024;

        private static readonly byte[] salt = Encoding.ASCII.GetBytes("£κκTT®ρ§Fψ®MTοψ#");
        /// <summary>
        /// this function will take a plaintext as an arg and
        /// returns ciphertext as an O/P
        /// </summary>
        /// <param name=”plaintext”></param>
        /// <returns></returns>
        public static string Encrypt(string plaintext)
        {
            var KeyBytes = new Rfc2898DeriveBytes(password, salt, iterations);
            //The deafault iteration count is 1000
            var alg = new RijndaelManaged {Key = KeyBytes.GetBytes(32), IV = KeyBytes.GetBytes(16)};
            var encryptStream = new MemoryStream();
            //Stream to write
            var encrypt = new CryptoStream(encryptStream, alg.CreateEncryptor(), CryptoStreamMode.Write);
            //convert plain text to byte array
            byte[] data = Encoding.UTF8.GetBytes(plaintext);
            encrypt.Write(data, 0, data.Length); //data to encrypt,start,stop
            encrypt.FlushFinalBlock();//Clear buffer
            encrypt.Close();
            return Convert.ToBase64String(encryptStream.ToArray());//return encrypted data
        }

        /// <summary>
        /// this function will take a ciphertext as an arg and
        /// returns plaintext as an O/P
        /// </summary>
        /// <param name=”plaintext”></param>
        /// <returns></returns>
        public static string Decrypt(string ciphertext)
        {
            var KeyBytes = new Rfc2898DeriveBytes(password, salt, iterations);
            //The deafault iteration count is 1000
            var alg = new RijndaelManaged {Key = KeyBytes.GetBytes(32), IV = KeyBytes.GetBytes(16)};
            var decryptStream = new MemoryStream();
            //Stream to read
            var decrypt = new CryptoStream(decryptStream, alg.CreateDecryptor(), CryptoStreamMode.Write);
            //convert plain text to byte array
            byte[] data = Convert.FromBase64String(ciphertext.Replace(' ', '+'));
            //This guy was throwing an error Invalid length for a Base-64 char array
            decrypt.Write(data, 0, data.Length); //data to encrypt,start,stop
            decrypt.Flush();
            decrypt.Close();
            return Encoding.UTF8.GetString(decryptStream.ToArray()); //return PlainText
        }
    }
}

⌨️ 快捷键说明

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