-3

I have code which takes a BigInteger

48451322989516520225703217657832557994348537500303367742400825550923100192302069868489479191146175399344044876949227990959739850227034985347595351425385263774028421913031512265649684935654507691239234667482091135118571200215310568615906290473167269182601320011893758047720172195848415075205065039282385885704

And after I perform bigint.toString(16) I get this string:

44ff39b391fe68e6522d4e2fd99a6c5c77afdae691357f04e5e504790460e7a8e30b3d988e2c1ad316660af7d4e70c012ab711bb77a238f7c2281903523446677f3f26b5d7338c77939f9d97268125adf309aba85e9113f895e9d5179987ab02f3cc255c83e05579664cb08f79390373cb7cce5d280c6647091721567e029a08

which contains letters in it, so after I try and convert it back to a BigInteger I can't b/c it's telling me it's not a number b/c of the letters in the value.

How do you properly go from a BigInteger, to string, and then back to BigInteger? Here is what my code is:

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
Catherine
  • 77
  • 1
  • 8
  • 2
    I'd suggest you read the documentation on [BigInteger](http://docs.oracle.com/javase/7/docs/api/java/math/BigInteger.html#BigInteger(java.lang.String,%20int)) before implementing anything. –  Nov 23 '16 at 01:05

1 Answers1

1

BigInteger has a constructor that takes in a String for the value and an int denoting the radix (in your case, 16).

See the API docs, but here's you how use it:

BigInteger newBI = new BigInteger(myString, 16);
childofsoong
  • 1,918
  • 16
  • 23