hi~ everyone
I am a user using camel 2.18.2.
Currently I am testing the encryption/decryption of messages using two PCs.
The encryption algorithm uses AES/CBC/PKCS5Padding (256bit).
Here is the test procedure.
On the local pc where activemq is installed, the above test will be
successfully decoded.
---
java.io.IOException: javax.crypto.BadPaddingException: Given final block not
properly padded
at
javax.crypto.CipherInputStream.getMoreData(CipherInputStream.java:121)
at javax.crypto.CipherInputStream.read(CipherInputStream.java:239)
at javax.crypto.CipherInputStream.read(CipherInputStream.java:215)
at
org.apache.camel.converter.crypto.CryptoDataFormat.unmarshal(CryptoDataFormat.java:180)
at
org.apache.camel.processor.UnmarshalProcessor.process(UnmarshalProcessor.java:69)
at
org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:77)
at
org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:541)
at
org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201)
at org.apache.camel.processor.Pipeline.process(Pipeline.java:120)
at org.apache.camel.processor.Pipeline.process(Pipeline.java:83)
at
org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:201)
at
org.apache.camel.component.file.GenericFileConsumer.processExchange(GenericFileConsumer.java:451)
at
org.apache.camel.component.file.GenericFileConsumer.processBatch(GenericFileConsumer.java:218)
at
org.apache.camel.component.file.GenericFileConsumer.poll(GenericFileConsumer.java:182)
at
org.apache.camel.impl.ScheduledPollConsumer.doRun(ScheduledPollConsumer.java:174)
at
org.apache.camel.impl.ScheduledPollConsumer.run(ScheduledPollConsumer.java:101)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask.runAndReset(Unknown Source)
at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(Unknown
Source)
at
java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown
Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: javax.crypto.BadPaddingException: Given final block not properly
padded
at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:975)
at com.sun.crypto.provider.CipherCore.doFinal(CipherCore.java:833)
at com.sun.crypto.provider.AESCipher.engineDoFinal(AESCipher.java:446)
at javax.crypto.Cipher.doFinal(Cipher.java:2048)
at
javax.crypto.CipherInputStream.getMoreData(CipherInputStream.java:118)
... 22 more
---
It is an error that occurs when the key used for encryption differs from the
key used for decryption.
If so, how should I pass the secret key when encrypting / decrypting using
camel?
Is it included in the header? Or does the message itself contain a secret
key?
I have not been able to solve it for a few days.
I look forward to your kind reply.
Java source is
---
public class SpringCryptoDataFormatTest{
private static Key aesCbcKey;
static {
try {
KeyGenerator generator = KeyGenerator.getInstance("AES");
aesCbcKey = generator.generateKey();
} catch (NoSuchAlgorithmException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
@Test
public void test() throws Exception {
Main main = new Main();
main.setApplicationContextUri("/org/apache/camel/component/crypto/SpringCryptoDataFormatTest.xml");
main.start();
// Sleep to allow time to copy the files etc.
Thread.sleep(30 * 1000);
main.stop();
}
public static Key getAesCbcKey() {
return aesCbcKey;
}
public static byte[] getIV() throws UnsupportedEncodingException {
byte[] iv = {24, 23, 25, 93, 24, -14, -110, -97, -27, -73, -1,
77, 64,
58, 15, -23};
return iv;
}
}
---
--
View this message in context:
http://camel.465427.n5.nabble.com/activemq-camel-encrypt-decrypt-byte-message-Problem-tp5793945.html
Sent from the Camel