看一下这段代码问题在哪!!!
炫舞十风 2012-04-23 02:21:33 关于RSA加密算法 里面有三个参数n e d ,(n,e)-公钥 (n,d)-私钥 现在私钥加密,公钥解密
现在已经得到n,e,d 代码如下:
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
RSAParameters RSAInfo = RSA.ExportParameters(true);
string strN = BitConverter.ToString(RSAInfo.Modulus).Replace("-", "");
string strD = BitConverter.ToString(RSAInfo.D).Replace("-", "");
string strE = BitConverter.ToString(RSAInfo.Exponent).Replace("-", "");这些都是十六进制字符串形式
BigInteger biN = BigInteger.Parse("0" + strN, System.Globalization.NumberStyles.HexNumber);
BigInteger biD = BigInteger.Parse("0" + strN, System.Globalization.NumberStyles.HexNumber);
BigInteger biE = BigInteger.Parse("0" + strN, System.Globalization.NumberStyles.HexNumber);将字符串形式转换成大数
strA="22AA758271D153577E65487BD3AE554AA1D72377"; 明文strA
BigInteger biA = BigInteger.Parse("0" + strA, System.Globalization.NumberStyles.HexNumber);将十六进制明文转化成大数
BigInteger biEncry=BigInteger.ModPow(biA,biD,biN); //biEncry(密文)=biA(明文)^biD mod biN RSA加密算法
BigInteger biDncry=BigInteger.ModPow(biEncry,biE,biN);//解密文 biEncry(密文)^biE mod biN
为什么解密得到的biDncry与原明文biA不相同