2
我会发布我的代码。对困惑感到抱歉。为什么RSA使用相同的密钥和消息产生不同的结果?
StringBuilder texto1 = new StringBuilder("LALALLA");
byte[] x = texto1.toString().getBytes();
try {
Cipher cifrado = Cipher.getInstance("RSA/ECB/PKCS1Padding");
cifrado.init(Cipher.ENCRYPT_MODE, key1.getPublic());
x = cifrado.doFinal(x);
String texto;
texto = new String(x, "UTF-8");
JOptionPane.showInputDialog(publicKey.toString());
String teste = "";
for (int i = 0; i < x.length; i++) {
teste += x[i];
}
jTextPane1.setText(teste);
//cifrado.init(Cipher.DECRYPT_MODE, privatekey);
byte[] y;
// x= texto.getBytes();
//y = cifrado.doFinal(texto.getBytes());
//texto = new String(y,"UTF-8");
jTextPane2.setText(x.toString());
} ...
这是按钮上的操作中的代码。我运行此代码,使用相同的按键,每次,对加密texto1返回不同的结果像[[email protected]
或[[email protected]
首先:**是**,加密是**应该**做到这一点。第二:你打印的字符串是'byte []'的'toString()',它的内容完全不相关。 –
PKCS#1v1.5填充是危险的;如果可能,请考虑使用OAEP。 – ntoskrnl