ricmoo / aes-js Goto Github PK
View Code? Open in Web Editor NEWA pure JavaScript implementation of the AES block cipher and all common modes of operation for node.js or web browsers.
License: MIT License
A pure JavaScript implementation of the AES block cipher and all common modes of operation for node.js or web browsers.
License: MIT License
aesjs.utils.utf8.toBytes(aesjs.utils.utf8.fromBytes([254,33]))
Uint8Array(3) [238, 161, 128]
Why the input is not equal to the output?
Hello,
I am using Aes-js
module with my node.js development for encryption and decryption.
I'm trying to encrypt whole Json (help of convert this object into stringify)
. Then i try to decrypt it and i also got that stringify object. But when i parse that decrypted string then it shows error like
SyntaxError: Unexpected token in JSON at position 31
Here my node and npm version
Node:- v8.9.1
NPM:- 5.5.1
Here it is my code
var aesjs = require('aes-js');
var key = aesjs.utils.utf8.toBytes("39067A6F8088F81E9C2BB5D46A8C0F60");
var iv = aesjs.utils.utf8.toBytes("EFEF3C38B05F5871");
var text = JSON.stringify({username: 'abcd', password:'newPass'});
var textBytes = aesjs.padding.pkcs7.pad(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);
console.log("data", encryptedHex); // HERE I GOT ENCRYPTED STRING OF STRINGIFY OBJECT
var encryptedBytes = aesjs.utils.hex.toBytes(encryptedHex);
var aesCbc = new aesjs.ModeOfOperation.cbc(key, iv);
var decryptedBytes = aesCbc.decrypt(aesjs.padding.pkcs7.pad(encryptedBytes));
var decryptedText = aesjs.utils.utf8.fromBytes(decryptedBytes);
console.log("decrypt", decryptedText);
My decrypted string is print like {"username":"abcd","password":"newPass"}SjF咨偮!K㈎
And so that when i try to parse this string it will throw errors of invalid JSON position
Please help me here.
I'm stuck in this. What's going wrong here or else please suggest me my mistake.
Thank you in advance.
I am using the library on a client connecting to a node backend. The problem is that I am receiving an error Error: error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt.
I have checked and the same data input with same iv and same key, generates different encrytped hex on both sides. What catches my attention is that in one of the cases the hex usin AESJs on the client is much smaller than the one from Node.
Encrypting and decrypting on Node (isolated) and on the client run fine, the problem is when encrypt on the client and send to Node.
Is there any mode I should change that I am not aware of? I have tried all the IV initiaded modes with no luck. Below some examples:
Input data1: 'este é um teste'
Encrypted Hex1 Node: 0b247a5b635d84639cc02722bd8257f256bc2fd7b12fcacdc8d082e9f6951bf7
Ecnrypted Hex1 Client: 554fb689bca935a2a92278739c23d353Comments
Input data2: '{"CPF":"29278804843","action":"verificarCPF","nonce":"6f1ae96b7ba43d4f1985fa37d"}'
Encrypted Hex2 Node: c575af80bde78b8040aa5b4d37ff0204eba68fcfbe004453e9b41e964303ee2fac43ff50bdd2e62a893b34fbeef3731c573672934640383818eefc77e1f052f7eec9795ee47465e249159f529e14599ff85f296c4e67fc3bcbde89af969b6d52
Encrypted Hex2 Client: e340c06df883d4dacf9fe1a814dabee8ab5eaf39728ad2544348f60aa5909f78a0fdb3d8f3c17247ed37bed559b702788d6a6ed5029c768179415a918a771b49833047def73e97e5453fcd931241104b7e697668f4c66f359ee8b48ff418f1ff
Regards,
示例 对 “123456” 加密 秘钥为"0123456789abcdef"
http://tool.chacuo.net/cryptaes
128: 结果 D89D/OvFrItmxI9ct8JbAg==
256: 结果 1jRJ/9iod2JHfvbCFUO2ykRZKmOdm35U0uFWw+Mha0E=
现在我如何用你的代码得到 256 的结果
I am using this library to decrypt a CFB cipher 40 characters long, with a segment size of 16. It fails from this error:
if ((plaintext.length % this.segmentSize) != 0) {
throw new Error('invalid plaintext size (must be segmentSize bytes)');
}
However, when removing these line I am able to successfully decode the string.
Is this error incorrect? I was thinking segmentSize would be in bits and not bytes, so 40 bytes should be divisible into 16 bits without issue.
It is well-known that CTR mode is fundamentally broken without a random nonce, for the same reason that repeated key XOR is broken, but in this library, ModeOfOperation.CTR
, as far as I can tell, currently does not make use of a nonce.
https://security.stackexchange.com/questions/63188/whats-the-point-of-the-nonce-in-ctr-mode
p.s., minor nitpick, but "initialization vector" is also spelled wrong in all the errors.
Just checking to see if Buffer is available, i.e.:
if (typeof(Buffer) == 'undefined') {
causes browserify to pull in the entire SlowBuffer. This is unnecessary, since we do not rely on it.
We can easily use typed arrays now that they are widely supported by all major browsers with the one caveat to be careful of slice()
, as some browsers do not implement it (use Array.prototype.slice.call()
instead.
Is it possible to encryption with SIV mode (RFC 5297)?
Hello!
It is not quite straightforward how to transfer the encrypted data, since its a byte array.
Many could think (as I did) that the encrypted byte array could be converted to a string with aesjs.util.convertBytesToString, being transferred over the wire, then converted back to a byte array with aesjs.util.convertStringToBytes for decryption.
Sadly this is not the case, since the included functions fails on these tasks (I guess the utilized encodeURI and such functions cannot handle the encrypted strings).
I've figured out that altering the above mentioned 2 functions to Google Closures "stringToByteArray" and "byteArrayToString" ones solves the issues, and its even faster.
(Hint link: https://github.com/google/closure-library/blob/e877b1eac410c0d842bcda118689759512e0e26f/closure/goog/crypt/crypt.js)
Sincerely,
Zoltan Hajdu
support auto padding when plaintext is not a multiple of 16 bytes.
See #16 for more details.
Basically, mCrypt is an old library for PHP which has legacy support for modes of operation which are no longer recommended, but whose names collide with official algorithms.
I just need to add an FAQ to the README to explain that to interoperate with mCrypt, you must use its NOFB to be equivalent to the official (and the method used in aes-js) OFB algorithm. There is also no equivalent to mCrypt's OFB in aes-js.
I am implement 128 aes encrypt and decrypt on node-red using node js .
i also mention the bellow function getting an error "Array contains invalid value"
function decrypt128(crt_text){
var key = aesjs.utils.utf8.toBytes(password)
var encryptedHex = crt_text;
console.log("dynamic-------- " + crt_text);
var encryptedBytes = aesjs.utils.hex.toBytes(encryptedHex);
var aesEcb = new aesjs.ModeOfOperation.ecb(key);
var decryptedBytes = aesEcb.decrypt(encryptedBytes);
var decryptedText = aesjs.utils.utf8.fromBytes(decryptedBytes);
return decryptedText;
}
it is properly working i add to the static var encryptedHex ="71149ac26898a42f6a6c8ddb9390f261" that is working fine. when i add dynamic value then got a error .
Thanks
fixed and pull request : #45 (comment)
As far as I know with my limited knowledge modes like XTS are good for data at rest and OCB for data transfers. CBC is not that useful without MAC. I don't get why you bother with implementing a not recommended mode like ECB and leave out the important ones.
Thanks for providing this library @ricmoo , I am finding this very useful.
How do I calculate the counter given an offset into the cipher text?
I know the initial counter used for encryption.
I have a partial ciphertext and I know the byte offset into the complete cipher text.
Looking through the sources at how the counter is incremented as the decrypt takes place seemed that it should be straight forward but trying a simple test does not show the plaintext.
Here is what I have been trying (simplified)
var bytesToRead = 500;
var fileOffset = 200;
var val = fileOffset / 16;
var counter = new aesjs.Counter(0);
while (val > 0) {
val--;
counter.increment();
}
var key = new Buffer(options.key);
var ciphertextFile = path.resolve(__dirname, 'package.json.enc');
var decrypter = new aesjs.ModeOfOperation.ctr(key, counter);
fs.open(ciphertextFile, 'r', function(status, fd) {
var buffer = new Buffer(bytesToRead);
fs.read(fd, buffer, 0, bytesToRead, fileOffset, function() {
var padded = aesjs.padding.pkcs7.pad(buffer);
var plaintext = decrypter.decrypt(padded);
var text = aesjs.utils.utf8.fromBytes(plaintext);
console.log('decrypted text: ', text);
});
});
I want to check if the data which I need to decrypt is already encrypted or not.
I need to decrypt a file.
I read a video file as a string.
Do I need to turn it base64 or other formats?
var key = aesjs.utils.utf8.toBytes('qe$sg#oin*@Znm*X');
var textBytes = aesjs.utils.utf8.toBytes(datastr);
var aesEcb = new aesjs.ModeOfOperation.ecb(key);
var decryptedBytes = aesEcb.decrypt(textBytes);
var decryptedText = aesjs.utils.utf8.fromBytes(decryptedBytes);
console.log(decryptedText);
Hello,
I noticed that utf8.fromBytes creates an array of strings and later on joins them.
At least on my Windows machine, running the latest chrome, it is much faster to simply do the "naive" thing and concat strings together. I assume it also uses much less memory, but I didn't profile that. I've been testing with strings that are a bit over 12MB long, and the difference is noticeable (from over 10s to <1s).
Also, using array.push(value) is really slow compared to doing array[array.length] = value;
This is probably not a problem in the general use-case, but it might have a significant impact on projects that run on mobiles, due to the slower CPUs and smaller RAM.
function toStr(bytes){
var result = "", i = 0, l = 0, max = bytes.length;
while (i < max) {
var c = bytes[i];
if (c < 128) {
result += String.fromCharCode(c);
i++;
} else if (c > 191 && c < 224) {
result += String.fromCharCode(((c & 0x1f) << 6) | (bytes[i + 1] & 0x3f));
i += 2;
} else {
result += String.fromCharCode(((c & 0x0f) << 12) | ((bytes[i + 1] & 0x3f) << 6) | (bytes[i + 2] & 0x3f));
i += 3;
}
}
return result;
}
Based on my understanding, the CBC mode works for any plaintext which length is multiple of segment size. If there is automatically padding mechanism, the length of plaintext can be any.
But in your implementation, this length of plaintext is required to be 16 bytes, which is hard to use in real cases. Hope that you would take it into consideration : )
Thanks for your fantastic code, really helpful!
I have this issue: stringToBytes(bytesToString(input)) != input
When I run this CTR example, everything works nicely:
var key = aesjs.util.convertStringToBytes("Example128BitKey");
// Convert text to bytes
var text = 'Text may be any length you wish, no padding is required.';
var textBytes = aesjs.util.convertStringToBytes(text);
// The counter is optional, and if omitted will begin at 0
var aesCtr = new aesjs.ModeOfOperation.ctr(key, new aesjs.Counter(5));
var encryptedBytes = aesCtr.encrypt(textBytes);
// The counter mode of operation maintains internal state, so to
// decrypt a new instance must be instantiated.
var aesCtr = new aesjs.ModeOfOperation.ctr(key, new aesjs.Counter(5));
var dec:ryptedBytes = aesCtr.decrypt(encryptedBytes);
// Convert our bytes back into text
var decryptedText = aesjs.util.convertBytesToString(decryptedBytes);
console.log(decryptedText);
// "Text may be any length you wish, no padding is required."
However, when I add these lines in the middle (just above 'The counter mode of operation...'), the output is garbled:
var encryptedBytesString = aesjs.util.convertBytesToString(encryptedBytes);
var encryptedBytes = aesjs.util.convertStringToBytes(encryptedBytesString);
So apparently, converting to string and then back to bytes, somehow changes the original bytes.
I compared the two byte strings, and they differ at most positions, so it's not going wrong with just the first or last byte.
Background: I would like to convert the encrypted bytes your nice library creates to strings in some form of storage within an element in the DOM, and later use your stringToBytes function on these strings to get back the arrays of encrypted bytes that I can then decrypt.
But in any case, I think stringToBytes(bytesToString(input))
should be equal to input
.
Thanks again for your great work on this library!
When using new ModeOfOperationCBC(AES_key, atob('z0lxWTiiD8ucFdf+aLSZ+A=='))
, function coerceArray(arg, copy)
will not be able to process the Base64Decoded iv and throw new Error('unsupported array-like object')
.
I have a key, its type is a string 'qe$sg#oin*@znm*X'
how can I turn it to 16bytesfor decryption?
Hi, I'd like to see initial vector implemented in this library. I don't know how to implement this myself but it would help immensely
Maybe I am confused.. How do I take a string "jahsdf"
and make it 16 byte so that I can encrypt it? I am using the CBC encryption and I am stuck converting my password to 16 byte. Any help would be much appreciated! I am getting a invalid plaintext size (must be multiple of 16 bytes)
The output of the CBC mode encryption different when the condition if (typeof(Buffer) === 'undefined')
changes.
I'm not really sure if this is the expected behavior ?
I have found an issue @line 584. There is the patch:
if (counter === null || counter === undefined) {
counter = new Counter()
}
The CBC encrypt method is setting the IV to the last block of the textcipher.
The IV should not be known before encryption. An attack on SSL2.0 based on that principle can be found at:
https://en.wikipedia.org/wiki/Transport_Layer_Security#BEAST_attack
Could we generate a random IV and append/prepend it to the textcipher instead?
Hi, I need this combination AES/ECB/PKCS7Padding
because I am working for the govt project. Is there any solution or I should avoid it and use default methods to encrypt ?
How to decrypt with PKCS7 padding?
thanks.
Hi how are you?
I'm trying to use aes-js on node:
var key = [ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'r', 'i', 'u', 'k', 'a', 'v']
var aesCtr = new aesjs.ModeOfOperation.ctr(key, new aesjs.Counter(5));
On the line 2 I receive the error: "Array contains invalid value 0,".
Do you know whats this could be?
I appreciate your help in advance.
Hello,
I'm going to package aes-js for Debian. Could you please use GitHub tags for each release ? It is easier to follow changes for packagers.
Regards,
Xavier
I am having a XML
and I need to encrypt with one time session key. I tried many ways but when I pass new aesjs.ModeOfOperation.ecb('32 bit encrypted string');
it did not work. So I am confused in session key. If I pass XML
as textBytes = aesjs.utils.utf8.toBytes(text);
and try to encrypt I got this error invalid plaintext size (must be multiple of 16 bytes)
. Will you please share your suggestion ? Here is my demo XML which I want to encrypt with one time session key.
<?xml version="1.0"?>
<root>
<xmlbuilder>
<repo type="git">git://github.com/oozcitak/xmlbuilder-js.git</repo>
</xmlbuilder>
</root>
When new-ing up aesjs.ModeOfOperation.cfb
passing an incorrect length of key throws an error. However passing an incorrect iv length returns some sort of error object. It should throw an error also.
import {aesjs} from 'aes-js';
typescript, I use this way to import, but has error:
Uncaught (in promise): TypeError: Cannot read property 'utils' of undefined
TypeError: Cannot read property 'utils' of undefined
When use AES/ECB/PCKS7Padding to encrypt text, the result is defferent form aes-js and java.
Here is the js code using aes-js:
`// Convert text to bytes
var text = 'this is a string will be AES_Encrypt';
var textBytes = aesjs.utils.utf8.toBytes(text);
var padded = aesjs.padding.pkcs7.pad(textBytes);
// An example 128-bit key
var key = "UITN25LMUQC436IM";
var keyBytes = aesjs.utils.utf8.toBytes(key);
var aesEcb = new aesjs.ModeOfOperation.ecb(keyBytes);
var encryptedBytes = aesEcb.encrypt(padded);
// To print or store the binary data, you may convert it to hex
var encryptedHex = aesjs.utils.hex.fromBytes(encryptedBytes);
console.log(encryptedHex);
// When ready to decrypt the hex string, convert it back to bytes
var encryptedBytes = aesjs.utils.hex.toBytes(encryptedHex);
var encryptedText = aesjs.utils.utf8.fromBytes(encryptedBytes);
var base = new Base64();
var encryptedBase64 = base.encode(encryptedText);
//should be: fhTD0NNIzv4jUEhJuC1htFFXJ/4S/rL6tDCJPiNvJ8mVLHWOD0HWweuxHynxoZf9
// Since electronic codebook does not store state, we can
// reuse the same instance.
//var aesEcb = new aesjs.ModeOfOperation.ecb(key);
var decryptedBytes = aesEcb.decrypt(encryptedBytes);
// Convert our bytes back into text
var decryptedText = aesjs.utils.utf8.fromBytes(decryptedBytes);
console.log(decryptedText);
// "this is a string will be AES_Encrypt"
function Base64() {
// private property
_keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
// public method for encoding
this.encode = function (input) {
var output = "";
var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
var i = 0;
input = _utf8_encode(input);
while (i < input.length) {
chr1 = input.charCodeAt(i++);
chr2 = input.charCodeAt(i++);
chr3 = input.charCodeAt(i++);
enc1 = chr1 >> 2;
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
enc4 = chr3 & 63;
if (isNaN(chr2)) {
enc3 = enc4 = 64;
} else if (isNaN(chr3)) {
enc4 = 64;
}
output = output +
_keyStr.charAt(enc1) + _keyStr.charAt(enc2) +
_keyStr.charAt(enc3) + _keyStr.charAt(enc4);
}
return output;
}
// public method for decoding
this.decode = function (input) {
var output = "";
var chr1, chr2, chr3;
var enc1, enc2, enc3, enc4;
var i = 0;
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
while (i < input.length) {
enc1 = _keyStr.indexOf(input.charAt(i++));
enc2 = _keyStr.indexOf(input.charAt(i++));
enc3 = _keyStr.indexOf(input.charAt(i++));
enc4 = _keyStr.indexOf(input.charAt(i++));
chr1 = (enc1 << 2) | (enc2 >> 4);
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
chr3 = ((enc3 & 3) << 6) | enc4;
output = output + String.fromCharCode(chr1);
if (enc3 != 64) {
output = output + String.fromCharCode(chr2);
}
if (enc4 != 64) {
output = output + String.fromCharCode(chr3);
}
}
output = _utf8_decode(output);
return output;
}
// private method for UTF-8 encoding
_utf8_encode = function (string) {
string = string.replace(/\r\n/g,"\n");
var utftext = "";
for (var n = 0; n < string.length; n++) {
var c = string.charCodeAt(n);
if (c < 128) {
utftext += String.fromCharCode(c);
} else if((c > 127) && (c < 2048)) {
utftext += String.fromCharCode((c >> 6) | 192);
utftext += String.fromCharCode((c & 63) | 128);
} else {
utftext += String.fromCharCode((c >> 12) | 224);
utftext += String.fromCharCode(((c >> 6) & 63) | 128);
utftext += String.fromCharCode((c & 63) | 128);
}
}
return utftext;
}
// private method for UTF-8 decoding
_utf8_decode = function (utftext) {
var string = "";
var i = 0;
var c = c1 = c2 = 0;
while ( i < utftext.length ) {
c = utftext.charCodeAt(i);
if (c < 128) {
string += String.fromCharCode(c);
i++;
} else if((c > 191) && (c < 224)) {
c2 = utftext.charCodeAt(i+1);
string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
i += 2;
} else {
c2 = utftext.charCodeAt(i+1);
c3 = utftext.charCodeAt(i+2);
string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
i += 3;
}
}
return string;
}
}`
Here is the java code:
`import java.security.Key;
import java.security.Security;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.apache.commons.codec.binary.Base64;
public class TestAes {
private static final String AESTYPE ="AES/ECB/PKCS7Padding";
public static String AES_Encrypt(String keyStr, String plainText) {
byte[] encrypt = null;
try{
Key key = generateKey(keyStr);
Cipher cipher = Cipher.getInstance(AESTYPE, "BC");
cipher.init(Cipher.ENCRYPT_MODE, key);
encrypt = cipher.doFinal(plainText.getBytes());
}catch(Exception e){
e.printStackTrace();
}
return new String(Base64.encodeBase64(encrypt));
}
public static String AES_Decrypt(String keyStr, String encryptData) {
byte[] decrypt = null;
try{
Key key = generateKey(keyStr);
Cipher cipher = Cipher.getInstance(AESTYPE, "BC");
cipher.init(Cipher.DECRYPT_MODE, key);
decrypt = cipher.doFinal(Base64.decodeBase64(encryptData));
}catch(Exception e){
e.printStackTrace();
}
return new String(decrypt).trim();
}
private static Key generateKey(String key)throws Exception{
try{
SecretKeySpec keySpec = new SecretKeySpec(key.getBytes(), "AES");
return keySpec;
}catch(Exception e){
e.printStackTrace();
throw e;
}
}
public static void main(String[] args) {
Security.addProvider(new BouncyCastleProvider());
String keyStr = "UITN25LMUQC436IM";
String plainText = "this is a string will be AES_Encrypt";
String encText = AES_Encrypt(keyStr, plainText);
String decString = AES_Decrypt(keyStr, encText);
System.out.println(encText);
System.out.println(decString);
}
}`
When encrypting and decrypying large amount og data, it would be nice with some kind of progress indicator. Support of callback function would be nice :-)
Please include licence remark into js.
Hi,
The README file does not mention if the implementation is in constant-time, can you maybe shed some light on that matter?
Thanks
I would like to create the key out of a String that I am getting from server side.
The key is constructed in java : byte[] raw = new sun.misc.BASE64Decoder().decodeBuffer(keyStr);
The JavaScript now accepts a var key = [....], however how to translate the java version to a key accepted on aes-js?
Either convertBytesToString
or convertStringToBytes
is bugging out in this case:
var bytes = [182,42,190,168]
var text2 = aes.util.convertBytesToString(bytes)
var bytes2 = aes.util.convertStringToBytes(text2)
console.log(bytes)
console.log(text2)
console.log(bytes2)
This is causing decryption (or possibly encryption) to fail for me.
Example Encryption key is "0123456789abcdef" and text is "123456"
http://tool.chacuo.net/cryptaes
(choice:ECB,pkcs7padding,256bit,utf-8)
128: Result D89D/OvFrItmxI9ct8JbAg==
256: Result 1jRJ/9iod2JHfvbCFUO2ykRZKmOdm35U0uFWw+Mha0E=
Now how do I get 256 results(1jRJ/9iod2JHfvbCFUO2ykRZKmOdm35U0uFWw+Mha0E=
) with your code
I am integrating the service of a provider in magento2, the integration requires adding an external js file that contains the library aes-js and others. This external file marks me with the error "aesjs is not defined", I look in the code of this library and see
} else if (typeof (define) === 'function' && define.amd) {
define (aesjs);
What is the correct way to use aesjs with amd?
I am using the aes.js on a phonegap app, and this appeared on 1 version of android. I am wondering if you would have any idea what this means?
Object function ArrayBuffer() { [native code] } has no method 'isView'
Thanks !
There has been many issues and contacts regarding the use of the string encoding/decoding utility functions.
This will be a major version change. This will probably also involve moving all algorithms to use Uint8Array
, which means aes-js will no longer work for very old browsers.
Basically, I need to rename the functions to help people identify which encodings are valid for binary data and which are only for human readable data.
Thinking:
aesjs.utils.binaryToHex(binaryData*) => string
aesjs.utils.hexToBinary(hexString) => Uint8Array
aesjs.utils.utf8ToBinary(string) => Uint8Array
aesjs.utils.binaryToUtf8(binaryData*) => string **
// Maybe support base64?
aesjs.utils.binaryToBase64(binaryData*) => string
aesjs.utils.base64ToBinary(string) => Uint8Array
** Make note that this function may not be reversible by utf8ToBinary (especially if you just pass random binary data into it)
Hi,
I have a quesion about how padding works in CBC mode (128bit). If I have a 128bit plain text, will padding increase the size to 256bits? I believe this is how it works in node's crypto library when autopadding
is left on.
If the size is increased, is there any way to turn padding off?
The actual implementation links the ciffer with the encryption key:
var aesEcb = new aesjs.ModeOfOperation.ecb(key);
var encryptedBytes = aesEcb.encrypt(textBytes);
It do not allow to reuse the same ciffer instance with another key. This is especially useful to improve performance to encryp/decrypt multiple time.
Is that possible to allow us to change the used key?
var aesEcb = new aesjs.ModeOfOperation.ecb();
aesEcb.defineKey(key):
var firstEncryptedBytes = aesEcb.encrypt(textBytes);
aesEcb.defineKey(anotherKey):
var secondEncryptedBytes = aesEcb.encrypt(textBytes);
Any benefit to using this over crypto-js and/or benchmarks?
Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.