日期:2014-05-18 浏览次数:20537 次
//加密 byte[] enData; private void encrypt(){ string str = txtContent.Text; byte[] data = System.Text.ASCIIEncoding.ASCII.GetBytes(str); X509Certificate2 cert = new X509Certificate2("C:\\abc.cer"); RSACryptoServiceProvider rsa = (RSACryptoServiceProvider)cert.PublicKey.Key; enData = rsa.Encrypt(data, false);//加密,得到加密后的字节组(该步骤是成功的) }
//解密 private void decrypt(){ X509Certificate2 cert = new X509Certificate2("C:\\abc.pfx", "123"); RSACryptoServiceProvider rsa = (RSACryptoServiceProvider)cert.PrivateKey; byte[] data = rsa.Decrypt(enData, false);//解密(报错了:不正确的项) }