ricmoo / aes-js

A pure JavaScript implementation of the AES block cipher and all common modes of operation for node.js or web browsers.
MIT License
1.45k stars 272 forks source link

Decrypt AES with CTR mode and IV #79

Closed Abdullah0991 closed 5 years ago

Abdullah0991 commented 5 years ago

Hi, I have an encrypted text using AES CTR and IV. As I saw in the examples the standard decryption code will be like:

var aesCtr = new aesjs.ModeOfOperation.ctr(key, new aesjs.Counter(5));
var decryptedBytes = aesCtr.decrypt(encryptedBytes);
var decryptedText = aesjs.utils.utf8.fromBytes(decryptedBytes);

First I use the library with Angular 7 and nodejs. Second, how can I set the IV parameter to the 'decrypt' method ?

Any help will be appreciated.

ricmoo commented 5 years ago

You set the IV to 5 in your example above. The IV for ctr mode is the initial value of the Counter. :)

Abdullah0991 commented 5 years ago

Hmmmmm, my IV is a string so I have to pass the string to Counter constructor ?

ricmoo commented 5 years ago

Your IV will need to be an Arraylike, so you will have to convert it first. The aes-js library does not attempt to do any guessing or coercing. Everything passed into it should be an Array of bytes in one way or another.

Abdullah0991 commented 5 years ago

Thanks, I already solve my problem. Appreciate your awesome lib.

renxiangxiangx commented 4 years ago

谢谢,我已经解决了我的问题。 欣赏你很棒的库。

你好 能给出个例子 说明下 是怎么对iv 进行处理的吗 这边想要一个CTR的AES 加解密js 实现