2016-06-11 81 views
0

我正在使用RSA加密創建消息傳遞應用程序。在這裏,我想將我的密文轉換爲一個BigInteger字符串。我這樣做將字符串轉換爲BigInteger

String ciphertext = message.getText(); 

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

message.setText(receivedPlaintext); 

它解密接收到的文本它顯示錯誤,如在同一窗口,但像不同的窗口工作正常:

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

你能給我一個解決方案嗎?

+1

異常的堆棧跟蹤打印告訴你*正是*什麼是錯的,關鍵要解決這個是學習批判性閱讀並從中吸取教訓。 –

回答

3

你與周圍的空白得到的數字,所以你應該修剪那些:

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

非常感謝。它爲我工作:) –