Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 54939200C1D for ; Thu, 16 Feb 2017 09:06:58 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 5328A160B61; Thu, 16 Feb 2017 08:06:58 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 9E5F1160B57 for ; Thu, 16 Feb 2017 09:06:57 +0100 (CET) Received: (qmail 12608 invoked by uid 500); 16 Feb 2017 08:06:56 -0000 Mailing-List: contact users-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@camel.apache.org Delivered-To: mailing list users@camel.apache.org Delivered-To: moderator for users@camel.apache.org Received: (qmail 54727 invoked by uid 99); 16 Feb 2017 04:39:07 -0000 X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 3.086 X-Spam-Level: *** X-Spam-Status: No, score=3.086 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, RCVD_IN_DNSWL_NONE=-0.0001, SPF_SOFTFAIL=0.972, URIBL_BLOCKED=0.001, URI_HEX=1.313] autolearn=disabled Date: Wed, 15 Feb 2017 21:38:51 -0700 (MST) From: Juno To: users@camel.apache.org Message-ID: <1487219931946-5793945.post@n5.nabble.com> Subject: activemq+camel encrypt/decrypt byte message Problem MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit archived-at: Thu, 16 Feb 2017 08:06:58 -0000 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 - Users mailing list archive at Nabble.com.