Skip to Main Content

Java and JavaScript in the Database

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

AES encryption from SunJCE provider results in undecryptable output

64638ee6-8a20-4938-b6c8-4f590536e83dJan 26 2016 — edited Jan 26 2016

I'm encrypting strings via an oracle package that uses a java class loaded into the database.

Database jvm is 1.5. Oracle database version is 11.2.0.3.0. The operating system is Solaris.

The encryption algorithm is AES with CBC and PKCS5PADDING padding.

The provider is SunJCE.

This is the code:

Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING");

final SecretKeySpec secretKey = new SecretKeySpec(key, "AES");

cipher.init(Cipher.ENCRYPT_MODE, secretKey, new IvParameterSpec(iv));

cipher.doFinal(strToEncrypt.getBytes());

The problem is that the encryption output cannot be decrypted using the same algorithm/key/iv etc.

The encryption output bytes seem to corrupted in the following manner:

correct result: x1,x2, ....xn, a,b,c,d

actual result: x1,x2, .... ,xn,c,b,0,d

where x1,..xn, a,b,c,d are bytes and 0 is the 0x00 byte.

Did anyone encountered this issue? I would appreciate any hint on how to isolate/troubleshoot it.

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 23 2016
Added on Jan 26 2016
0 comments
1,004 views