【发布时间】:2011-02-24 12:58:33
【问题描述】:
我目前正面临 BadPaddingException 错误。我正在将加密数据从客户端发送到服务器。服务器将根据收到的数据进行解密。
谁能帮我看看代码并指出错误,拜托。
客户端
try{
Cipher c = Cipher.getInstance("RSA");
c.init(Cipher.ENCRYPT_MODE, servPubKey);
String myMessage = "this is a secret message";
byte[] msgByte = myMessage.getBytes();
ObjectOutputStream outVehicle3 = new ObjectOutputStream(socket.getOutputStream());
ParamClass print4 = new ParamClass (cipherText);
outVehicle3.writeObject(print4);
} catch (Throwable e) {
// TODO Auto-generated catch block
tv.append("\nUnable to perform RSA encryption!");
e.printStackTrace();
}
服务器端
ObjectInputStream inServ3 = new ObjectInputStream(socket.getInputStream());
try{
ParamClass print5 = (ParamClass) (inServ3.readObject());
Cipher dec = Cipher.getInstance("RSA");
dec.init(Cipher.DECRYPT_MODE, serverPrivateKey);
byte[] dectyptedText = dec.doFinal(print5.cipherText);
String decipherText = dectyptedText.toString();
System.out.println("\nDecrypted Message to string: " + decipherText);
}catch (Throwable e) {
e.printStackTrace();
System.out.println("Unable to perform RSA decryption!");
}
它表示错误发生在以下行中。
byte[] dectyptedText = dec.doFinal(print5.cipherText);
提前感谢您的帮助和指导。
【问题讨论】:
标签: java rsa padding encryption