1

I want encryption and decryption of a Uint8Array for that i have downloaded CryptoJS library from this link.

I have tested aes cipher algorithm on a dummy string its working fine.

Now i want it to implement it on Uint8Array. This array is holding a video file data.

Since the encryption and decryption works on a string, i have to convert it to a string for that i have referenced this question posted on the stackoverflow click here

Code for encryption is :

var encrypted = CryptoJS.AES.encrypt(String.fromCharCode.apply(null, uInt8Array), "test");

But when i ran the code following error is coming:

 Uncaught RangeError: Maximum call stack size exceeded 

How do i make it working?

Community
  • 1
  • 1
Pankaj Khurana
  • 3,243
  • 10
  • 50
  • 79

1 Answers1

2

That error is due the String.fromCharCode.apply(null, uInt8Array) part, CryptoJS is never called.

Note that full syntax of fromCharCode is String.fromCharCode(n1, n2, ..., nX), so all elements of the given buffer must be moved to the stack in order to apply the function.

You must be using a very big buffer, a video file you said, so that must be the reason you got a stackoverflow error.

Try to use a `CryptoJS.lib.WordArray' instead, as described here:

http://groups.google.com/group/crypto-js/browse_thread/thread/4ce6fddad709954d?pli=1

Juan Mellado
  • 14,973
  • 5
  • 47
  • 54
  • Thanks juan for replying. Yeh this buffer contains video file data (v11.webm 10.5 MB). How can i apply encryption/decryption? – Pankaj Khurana Jan 04 '13 at 08:49
  • @PankajKhurana I'm not a CryptoJS user, just pointing you in the right direction. Anyway, a quick look at library documentation reveals that _"the cipher algorithms accept either strings or instances of CryptoJS.lib.WordArray"_. I think you could follow from there, I would do it. – Juan Mellado Jan 04 '13 at 10:09
  • i had a look at it but could not find any relevant info. can you please suggest me some other library which can get the job done? – Pankaj Khurana Jan 04 '13 at 10:59