[英]How do i encrypt and decrypt Uint8Array using javascript?
I want encryption and decryption of a Uint8Array for that i have downloaded CryptoJS library from this link . 我希望加密和解密Uint8Array,因为我已从此链接下载了CryptoJS库。
I have tested aes cipher algorithm on a dummy string its working fine. 我已经在虚拟字符串上测试了aes密码算法,它的工作正常。
Now i want it to implement it on Uint8Array. 现在我希望它在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 由于加密和解密适用于字符串,我必须将其转换为字符串,我已经引用此问题发布在stackoverflow上点击此处
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? 我如何使它工作?
That error is due the String.fromCharCode.apply(null, uInt8Array)
part, CryptoJS is never called. 该错误是由
String.fromCharCode.apply(null, uInt8Array)
部分引起的,从不调用CryptoJS。
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. 请注意,
fromCharCode
完整语法是String.fromCharCode(n1, n2, ..., nX)
,因此必须将给定缓冲区的所有元素移动到堆栈才能apply
该函数。
You must be using a very big buffer, a video file you said, so that must be the reason you got a stackoverflow error. 你必须使用一个非常大的缓冲区,你说的视频文件,所以这必然是你遇到stackoverflow错误的原因。
Try to use a `CryptoJS.lib.WordArray' instead, as described here: 尝试使用`CryptoJS.lib.WordArray',如下所述:
http://groups.google.com/group/crypto-js/browse_thread/thread/4ce6fddad709954d?pli=1 http://groups.google.com/group/crypto-js/browse_thread/thread/4ce6fddad709954d?pli=1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.