Shuvo oshuvo Shuvo oshuvo - 1 year ago 78
Java Question

Converting String to BigInteger

I am creating a messaging application using RSA encryption. Here I want to convert my ciphertext which is a string into a BigInteger . I have done this

String ciphertext = message.getText();

String receivedPlaintext = new String(decryption.decrypt(new BigInteger(ciphertext)));


It works fine on the same window but on different window like when decrypting the received text it shows error like :

Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "52485972 "

can you give me a solution ?

Answer Source

You are getting numbers with whitespace around them, so you should trim those:

String receivedPlaintext = new String(decryption.decrypt(new BigInteger(ciphertext.trim())));