Comments (6)
But when I'm using ECB mode, this error occurs too.
And in Java, the bytes array is not limited to 16*N bytes.
from aes-js.
CBC Operates against blocks, so the data length must be a multiple of 16.
See the CBC section here: https://en.m.wikipedia.org/wiki/Block_cipher_mode_of_operation
Hope this helps. :)
from aes-js.
How to solve this problem, I also encountered this pit
from aes-js.
I don't know how to use it gracefully.Please help me write a better code.
------------------------------------------My code--------------------------------------------
function aesEcpt(text, pwd) {
var shp = sha256_digest(pwd);
var key = [];
var iv = [];
for (var i = 0; i < 32; i++) {
var itm = shp.charCodeAt(i);
if (i < 16)
key.push(itm);
else
iv.push(itm);
}
var textBytes = aesjs.utils.utf8.toBytes(text);
var aesCbc = new aesjs.ModeOfOperation.cbc(key, iv);
var encryptedBytes = aesCbc.encrypt(textBytes);
var encryptedHex = aesjs.utils.hex.fromBytes(encryptedBytes);
return encryptedHex;
}
function aesDcpt(text, pwd) {
var shp = sha256_digest(pwd);
var key = [];
var iv = [];
for (var i = 0; i < 32; i++) {
var itm = shp.charCodeAt(i);
if (i < 16)
key.push(itm);
else
iv.push(itm);
}
var encryptedBytes = aesjs.utils.hex.toBytes(text);
var aesCbc = new aesjs.ModeOfOperation.cbc(key, iv);
var decryptedBytes = aesCbc.decrypt(encryptedBytes);
var decryptedText = aesjs.utils.utf8.fromBytes(decryptedBytes);
return decryptedText;
}
from aes-js.
Perhaps Cipher Text Stealing should be implemented in CBC mode, to support arbitrary plaintext lengths:
https://en.wikipedia.org/wiki/Ciphertext_stealing
from aes-js.
Related Issues (20)
- Big endian HOT 2
- Is this still maintained? HOT 2
- Transform key and iv bytes in base64/Hex for another languages decript HOT 1
- export an es module HOT 2
- CBC encrypt and decrypt is wrong on output HOT 3
- CTR mode: Counter increment issue with 2 different IVs HOT 1
- Uncaught Error: invalid plaintext size (must be 16 bytes) HOT 3
- Recommending CTR is dangerous, if the same key is used twice HOT 7
- Encrypt CBC padding 7 is different from Java HOT 6
- Please add index.min.js
- need php/openssl advice HOT 1
- Make note of `yarn add -D @types/aes-js` in README HOT 1
- version 2.1.1 , ECB
- Incorrect UTF-8 decoding HOT 2
- Getting Chinese letters
- Should provide method to generate IV HOT 2
- Feature Request: Import key from hex HOT 1
- how do I encrypt images with this module
- How to convert a string to key? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from aes-js.