3

I'm looking for AES256 CBC decryption client side,

in nodeJS I use this function to encrypt:

exports.encrypt = function(txt, cryptkey){
  var cipher = crypto.createCipher('aes-256-cbc',cryptkey);
  var crypted = cipher.update(txt,'utf8','hex');
  crypted += cipher.final('hex');

  console.log(crypted);
  return crypted;

};

but I can't seem to work with it in any client side library (JSAES.js, SJCL.js, pidcrypt)

my guess is it has something to do with the base64/hex encoding decoding, any pointers?

1 Answer 1

8

Please have a look at the CryptoJS project:

Here is an example of AES256 CBC encryption / decryption:

Include:

<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/aes.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/mode-cfb-min.js"></script>

JS:

var passPhrase = "Secret Phassphrase";

var encrypted = CryptoJS.AES.encrypt("Message", passPhrase, { mode: CryptoJS.mode.CFB });
var decrypted = CryptoJS.AES.decrypt(encrypted, passPhrase, { mode: CryptoJS.mode.CFB });

console.log('encrypted', encrypted);
console.log('decrypted', decrypted.toString(CryptoJS.enc.Utf8));

View the demo at jsFiddle

Sign up to request clarification or add additional context in comments.

3 Comments

I included the "mode-cfb-min.js" on the server nodeJS and was able to encrypt cryptoJS server side AND client side, thanks!! :)
is it safe to store passPhrase at client side? Further, is it the same pass phrase we are using in encrypt function's parameter cryptkey?
1.) No, it is not safe to store it on the client side. The above code is just for demo purpose. 2.) Check the documentation github.com/brix/crypto-js :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.