Dead simple, no dependency, password protected AES-128-CBC encryption and decryption for browser
npm i @inventsable/smalltalk
import { encrypt, decrypt } from "@inventsable/smalltalk";
Encodes any valid string, object or array data with a given password to a CipherParams object containing ciphertext
, salt
and initialization vector
keys inline with CryptoJS
:
let encryptionResult = encrypt("Hello world", "Some secret passphrase");
console.log(encryptionResult);
// returns:
// {
// ct: "22GyQQsEP8ijVk8UfGdVFw==",
// iv: "e9076c31aebff3efdc85083a101bd44a",
// s: "271f382cf7baf088",
// }
Decodes any valid CipherParams string with a given password to its original value:
let decryptionResult = decrypt(
`{"ct":"22GyQQsEP8ijVk8UfGdVFw==","iv":"e9076c31aebff3efdc85083a101bd44a","s":"271f382cf7baf088"}`,
"Some secret passphrase"
);
console.log(decryptionResult); // returns "Hello world"