[Openssl] How to decrypt encrypted data from corona sdk in java?

My client made by corona sdk. Server is java base.

I have one issue. The encrypted data using corona sdk openssl plugin and encrypted data using java Cipher util are mismatch.

Corona SDK code

build.settings

    plugins =

    {

        [“plugin.openssl”] = { publisherId = “com.coronalabs”, },

    },

main.lua

local openssl = require( “plugin.openssl” )

local mime = require ( “mime” )

local cipher = openssl.get_cipher ( “aes-256-cbc” )

local en = cipher:encrypt ( “test message”, “1234567890123456” )

local encryptedData = mime.b64 ( en )

result :  O qTLwWNezBZuYboXXG3gOQ==

Java code

byte[] ivBytes = { 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00, 0X00 };

Cipher cipher = Cipher.getInstance(“AES/CBC/PKCS5Padding”, new IvParameterSpec(ivBytes));

SecretKeySpec keySpec = new SecretKeySpec(“1234567890123456”.getBytes(), “AES”);

byte[] encrypted = cipher.doFinal(“test message”.getBytes(“UTF-8”));

String enStr = new String(Base64.encodeBase64(encrypted));

 

result : ucNu/5WgckCVmmz/Ls2VqQ==

How can I get correct data?

You need to reverse the process in Java. That is you have to do a Base64.decodeBase64() on the string you got from Corona first, then decrypt it.

Rob

You need to reverse the process in Java. That is you have to do a Base64.decodeBase64() on the string you got from Corona first, then decrypt it.

Rob