AES256 - java callout

Want help with conversion of below req(third party call) to java wrapper in apigee. I have the java code but having issues with the conversion to use in Apigee proxy.

1. Get the key that was returned from the “Get Authentication Token” call. This key is a URL-encoded base 64 string.
2. Derive the initialization vector (IV) to be used for encryption. Do this in the following way:
a. URL-decode the key.
b. Convert the URL-decoded key from a base 64 string to a byte array.
c. Apply the SHA256 algorithm to the decoded key to get a hash.
d. Remove every other value of the result. (The SHA256 hash is 32 bytes, but the IV vector must be 16 bytes, so remove every other byte so that the IV is 16 bytes.)
3. Create a string that is (with no spaces) username char(30) password
4. AES256-encrypt the string from Step 3, using:
• The decoded key from Step 2a as the AES key.
• The derived IV from Step 2d as the AES IV.

aes.txt

Thanks,

0 3 586
3 REPLIES 3

When I use java callout & implement as per doc .. I see below error.

Please suggest.

2016-11-22 01:55:29,265  Apigee-Main-4 ERROR MESSAGING.RUNTIME - AbstractConfigurator.rollbackTransaction() : Error in processing the changes :
com.apigee.kernel.exceptions.spi.UncheckedException: Failed to instantiate the JavaCallout Class com.test.AesCrypto
        at com.apigee.steps.javacallout.JavaCalloutStepDefinition.newInstance(JavaCalloutStepDefinition.java:71) ~[javacallout-1.0.0.jar:na]
        at com.apigee.messaging.runtime.StepDefinition.getStepDefinitionExecution(StepDefinition.java:227) ~[message-processor-1.0.0.jar:na]
        at com.apigee.messaging.runtime.Step.createExecutionInstance(Step.java:86) ~[message-processor-1.0.0.jar:na]
        at com.apigee.messaging.runtime.Step.handleAdd(Step.java:65) ~[message-processor-1.0.0.jar:na]
        at com.apigee.messaging.runtime.Flow.addStep(Flow.java:122) ~[messa
        at java.util.concurrent.FutureTask.run(FutureTask.java:262) [na:1.7.0_75]
---
---
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [na:1.7.0_75]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [na:1.7.0_75]
        at java.lang.Thread.run(Thread.java:745) [na:1.7.0_75]
Caused by: java.lang.ClassCastException: com.test.AesCrypto cannot be cast to com.apigee.flow.execution.spi.Execution
        at com.apigee.steps.javacallout.JavaCalloutStepDefinition.createNewInstance(JavaCalloutStepDefinition.java:95) ~[javacallout-1.0.0.jar:na]
        at com.apigee.steps.javacallout.JavaCalloutStepDefinition.newInstance(JavaCalloutStepDefinition.java:66) ~[javacallout-1.0.0.jar:na]
        ... 32 common frames omitted

Issue is resolved as it was including expressions-1.0.0.jar and message-flow-1.0.0.jar jars. After removing the jars the issue is resolved & was able to deploy & implement with in apigee.

Hi @vinay

I am doing the same thing. I am wondering how you derive the IV? Does the client supply IV? If not how do you create an IV and store it for decryption?

Any help will be highly appreciated.

Thanks,

Krish