# 关于私钥加密,公钥解密的算法安全.网上介绍的大素数那个方法可靠么?求算法达人

0
[待解决问题]

功能：用指定的私钥(n,d)加密指定字符串source

string EncryptString(string source, BigInteger d, BigInteger n)
`private string EncryptString(string source, BigInteger d, BigInteger n)                 ...{                         int len = source.Length;                         int len1 = 0;                         int blockLen = 0;                         if ((len % 128) == 0)                                 len1 = len / 128;                         else                                 len1 = len / 128 + 1;                         string block = "";                         string temp = "";                         for (int i = 0; i < len1; i++)                         ...{                                 if (len >= 128)                                         blockLen = 128;                                 else                                         blockLen = len;                                 block = source.Substring(i * 128, blockLen);                                 byte[] oText = System.Text.Encoding.Default.GetBytes(block);                                 BigInteger biText = new BigInteger(oText);                                 BigInteger biEnText = biText.modPow(d, n);                                 string temp1 = biEnText.ToHexString();                                 temp += temp1;                                 len -= blockLen;                         }                         return temp;                 } `

string DecryptString(string source, BigInteger e, BigInteger n)
`private string DecryptString(string source, BigInteger e, BigInteger n)                 ...{                         int len = source.Length;                         int len1 = 0;                         int blockLen = 0;                         if ((len % 256) == 0)                                 len1 = len / 256;                         else                                 len1 = len / 256 + 1;                         string block = "";                         string temp = "";                         for (int i = 0; i < len1; i++)                         ...{                                 if (len >= 256)                                         blockLen = 256;                                 else                                         blockLen = len;                                 block = source.Substring(i * 256, blockLen);                                 BigInteger biText = new BigInteger(block, 16);                                 BigInteger biEnText = biText.modPow(e, n);                                 string temp1 = System.Text.Encoding.Default.GetString(biEnText.getBytes());                                 temp += temp1;                                 len -= blockLen;                         }                         return temp;                 } `

string EncryptProcess(string source, string d, string n)
`                private string EncryptProcess(string source, string d, string n)                 ...{                         byte[] N = Convert.FromBase64String(n);                         byte[] D = Convert.FromBase64String(d);                         BigInteger biN = new BigInteger(N);                         BigInteger biD = new BigInteger(D);                         return EncryptString(source, biD, biN);                 } `

DecryptProcess(string source, string e, string n)
`private string DecryptProcess(string source, string e, string n)                 ...{                         byte[] N = Convert.FromBase64String(n);                         byte[] E = Convert.FromBase64String(e);                         BigInteger biN = new BigInteger(N);                         BigInteger biE = new BigInteger(E);                         return DecryptString(source, biE, biN);                 }`
hax2 | 菜鸟二级 | 园豆：202

0

(e,n)是私钥，(d,n)是公钥==>它们之间是一对的关系

http://www.cnblogs.com/myitm/archive/2010/11/16/1878834.html

(e,n)是私钥，(d,n)是公钥==>它们之间是一对的关系

您需要登录以后才能回答，未注册用户请先注册