将BigInteger转换为String,然后再转换回BigInteger

时间:2016-11-23 00:59:16

标签: java string encryption cryptography biginteger

我有一个采用BigInteger的代码

48451322989516520225703217657832557994348537500303367742400825550923100192302069868489479191146175399344044876949227990959739850227034985347595351425385263774028421913031512265649684935654507691239234667482091135118571200215310568615906290473167269182601320011893758047720172195848415075205065039282385885704

在我执行bigint.toString(16)后,我得到了这个字符串:

44ff39b391fe68e6522d4e2fd99a6c5c77afdae691357f04e5e504790460e7a8e30b3d988e2c1ad316660af7d4e70c012ab711bb77a238f7c2281903523446677f3f26b5d7338c77939f9d97268125adf309aba85e9113f895e9d5179987ab02f3cc255c83e05579664cb08f79390373cb7cce5d280c6647091721567e029a08

其中包含字母,所以在我尝试将其转换回BigInteger之后我就可以告诉我它不是b / c中的字母b / c价值。

你如何正确地从BigInteger变为字符串,然后再返回BigInteger?这是我的代码:

BigInteger decryptedBI = resultBI.modPow(keyD, keyN);  // my biginteger
String decrypted = decryptedBI.toString(16); // converted it to a string value
System.out.println(decryptedBI);
System.out.println(decrypted); // this is the decrypted hash

1 个答案:

答案 0 :(得分:1)

> List2 => [93, 218, 219, 307, 526, 692, 1106, 1856, 2043] 有一个构造函数,其值为BigInteger,而String表示基数(在您的情况下为16)。

请参阅API docs,但您可以使用它:

int