将字符串转换为 BigInteger
Converting String to BigInteger
我正在创建一个使用 RSA 加密的消息传递应用程序。在这里,我想将我的密文(一个字符串)转换为一个 BigInteger 。我已经做到了
String ciphertext = message.getText();
String receivedPlaintext = new String(decryption.decrypt(new BigInteger(ciphertext)));
message.setText(receivedPlaintext);
它在同一个 window 上工作正常,但在不同的 window 上工作正常,比如在解密收到的文本时显示错误,如:
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "52485972 "
你能给我一个解决方案吗?
你得到的数字周围有空格,所以你应该 trim 那些:
String receivedPlaintext = new String(
decryption.decrypt(new BigInteger(ciphertext.trim()))
);
我正在创建一个使用 RSA 加密的消息传递应用程序。在这里,我想将我的密文(一个字符串)转换为一个 BigInteger 。我已经做到了
String ciphertext = message.getText();
String receivedPlaintext = new String(decryption.decrypt(new BigInteger(ciphertext)));
message.setText(receivedPlaintext);
它在同一个 window 上工作正常,但在不同的 window 上工作正常,比如在解密收到的文本时显示错误,如:
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "52485972 "
你能给我一个解决方案吗?
你得到的数字周围有空格,所以你应该 trim 那些:
String receivedPlaintext = new String(
decryption.decrypt(new BigInteger(ciphertext.trim()))
);