首页 > 代码库 > 加密器

加密器

 
///随机数
byte[] randomByte = new byte[16];//创建字节数组 //实例化加密随机数生成器 RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider(); rng.GetBytes(randomByte);//随机数填充数组 Guid randguid = new Guid(randomByte);//生成标识符 this.txt.Text = randguid.ToString();//显示

 

 /// <summary>        /// 字符串不对称加密和解密        /// </summary>               private RSACryptoServiceProvider rsa;//密码类        RSAParameters para;//参数        byte[] pridata;        public Form1()        {            InitializeComponent();            rsa = new RSACryptoServiceProvider();            para = rsa.ExportParameters(true);            rsa.Clear();            rsa = new RSACryptoServiceProvider();            rsa.ImportParameters(para);        }        private void Encrypt_Click(object sender, EventArgs e)        {            //转化加密文本            byte[] dataEncrypt = Encoding.UTF8.GetBytes(txtPlainText.Text);            byte[] encText = rsa.Encrypt(dataEncrypt, false);//加密            txtCipherText.Text = Encoding.UTF8.GetString(encText);//产生加密文本            pridata =http://www.mamicode.com/ encText;        }        private void Decrypt_Click(object sender, EventArgs e)        {            byte[] cyarray = rsa.Decrypt(pridata, false);            txtResultText.Text = Encoding.UTF8.GetString(cyarray);//解密         }

 

加密器