我正在尝试在两个代理之间发送加密消息。我有一个字符串,其中包含我转换为字节的信息对其进行加密,然后再次字符串以发送消息。收到消息但是,在接收代理我得到以下异常
javax.crypto.BadPaddingException: Decryption error
at sun.security.rsa.RSAPadding.unpadV15(Unknown Source)
at sun.security.rsa.RSAPadding.unpad(Unknown Source)
at com.sun.crypto.provider.RSACipher.doFinal(RSACipher.java:354)
at com.sun.crypto.provider.RSACipher.engineDoFinal(RSACipher.java:380)
at javax.crypto.Cipher.doFinal(Cipher.java:2121)
at Hi$1.action(Hi.java:72)
at jade.core.behaviours.Behaviour.actionWrapper(Behaviour.java:344)
at jade.core.Agent$ActiveLifeCycle.execute(Agent.java:1532)
at jade.core.Agent.run(Agent.java:1471)
at java.lang.Thread.run(Unknown Source)
我在同一个容器中尝试了代理的代码,它工作正常,但是,如果它们在不同的容器上,它不会。
这就是我加密消息的方式:
String msg1="Message from bob 1"; // message
MSGBOB = cipher.doFinal(msg1.getBytes("ISO-8859-1")); // encryption
msg.setContent(new String (MSGBOB,"ISO-8859-1")); // conversion to string
这就是我解密它的方式:
mm = msg.getContent().getBytes("ISO-8859-1");// received message
m = new String(cipher.doFinal(mm),"ISO-8859-1"); // decryption