Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encryption ChiperText not valid while doing decryption at java layer #31

Open
elavankarthik84 opened this issue Sep 10, 2020 · 2 comments

Comments

@elavankarthik84
Copy link

Dear Team,
We are using ionic v3 project and doing AES 256 encryption algorithm. the chiper Text not valid and it is not base64 format. how do we change the format to supported java. i have generated chiper Text as below format, it is working decryption within ionic project, if we use similar to other java layers. it is not able to decrypted. please helps.

format of chiper text : 77be64b6202dbbf43bfdce7669722b9c

@praveenraji2i
Copy link
Contributor

@elavankarthik84 Can you please give us more details to debug? Are you trying to access the decryption method from some other Java class?

@drik
Copy link

drik commented May 25, 2023

Late answer, but, it can still help someone. I was confronted with this concern with this plugin: if you encrypt data with this plugin, impossible to decrypt on another system (c# or java server/application ). When I looked at the source code of the plugin to understand how the encrypt and decrypt is done, I found that the key provided is not directly used to encrypt. The plugin generates another encryption key from the one provided. No other system except this same plugin will ever be able to decrypt data encrypted by this plugin, since the keys will always be different

private String encrypt(String secureKey, String value, String iv) throws Exception {

    byte[] pbkdf2SecuredKey = generatePBKDF2(secureKey.toCharArray(), PBKDF2_SALT.getBytes("UTF-8"),
            PBKDF2_ITERATION_COUNT, PBKDF2_KEY_LENGTH);

    IvParameterSpec ivParameterSpec = new IvParameterSpec(iv.getBytes("UTF-8"));
    SecretKeySpec secretKeySpec = new SecretKeySpec(pbkdf2SecuredKey, "AES");

    Cipher cipher = Cipher.getInstance(CIPHER_TRANSFORMATION);
    cipher.init(Cipher.ENCRYPT_MODE, secretKeySpec, ivParameterSpec);

    byte[] encrypted = cipher.doFinal(value.getBytes());

    return Base64.encodeToString(encrypted, Base64.DEFAULT);

}

The first two lines regenerate a key from the key provided to it in addition to other parameters that are specific to the plugin (PBKDF2_SALT, PBKDF2_ITERATION_COUNT, PBKDF2_KEY_LENGTH)
If you want to succeed decryption on Java side, you must also regenerate a new key using the same technique as in this plugin. I can provide a working Java code that can decrypt data encrypted with this plugin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants