В настоящее время я сталкиваюсь с ошибкой 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);
Заранее благодарим за вашу помощь и руководство.