Shuvo oshuvo Shuvo oshuvo - 4 months ago 5x
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 ?


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

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