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

Not able to decrypt the encrypted data on server side which was encrypted using CryproJS on client side.. #140

Open
GoogleCodeExporter opened this issue Mar 17, 2015 · 0 comments

Comments

@GoogleCodeExporter
Copy link

I want to encrypt some data on client side and Decrypt it on the server side 
but it is giving error on the server side saying that "Incorrect key".

Followings are my code snippets

        var key = "randomKey";

        var hash  = CryptoJS.MD5(key);

        var hashedKey = btoa(hash.toString(CryptoJS.enc.Base64));

        var iv  = "1234567812345678";
        var message   = "#This is the plain text to encrypt#";


        var encrypted = CryptoJS.AES.encrypt(message, hashedKey, {iv : iv, mode: CryptoJS.mode.CBC,padding: CryptoJS.pad.Pkcs7} );


        var encrypteData=encrypted.toString(CryptoJS.enc.utf8);

That's how I am encrypting at client side. and sending "iv", "hashedKey" and 
"encryptedData" to server side.

we are decrypting this encrypted data at server side using java. we are using 
AES/CBC/PKCS5Pading. By passing iv, key and encrypted message to the "doFinal" 
method but we are getting error message as "Given final block not padded 
properly"


Cipher decrypt = Cipher.getInstance("AES/CBC/PKCS5Padding");
                decrypt.init(Cipher.DECRYPT_MODE, hashedKey,iv);

        byte[] decryptedMsg = decrypt.doFinal(encryptedMsg);


What am i doing wrong?

Original issue reported on code.google.com by tiwari.a...@gmail.com on 14 Aug 2014 at 9:43

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

No branches or pull requests

1 participant