Data Encryption and Decryption wrapper around node js crpto module, Uses scrypt for key deriviation and handles the data encryption algorithm independent via <code>crypto.createCipheriv</code>. supports all algorithms that are able to use auth tags
npm install basic-cryptercrypto.createCipherIv, this is just a wrapper for the node crypto module which does all the heavy lifting``js
import { DataCrypter } from "basic-crypter"
const crypter = new DataCrypter();
const key = "test";
const data = "Very Secret Data";
const encrypted_data = await crypter.EncryptData(data,key);
const decrypted_data = await crypter.DecryptData(encrypted_data,key);
if (decrypted_data === data){
console.log("Success!");
}
`
js
import { DataCrypter } from "basic-crypter"// algorithm, key size (bytes), iv size (bytes)
const crypter = new DataCrypter("chacha20-poly1305", 32, 12);
const key = "test";
const data = "Very Secret Data";
const encrypted_data = await crypter.EncryptData(data,key);
const decrypted_data = await crypter.DecryptData(encrypted_data,key);
if (decrypted_data === data){
console.log("Success!");
}
`Encoding of input and output
By default the ouput of encryptData is a buffer and the output of decryptData is in utf8. Here is how you can change it.
`js
import { DataCrypter } from "basic-crypter"// leave rest undefined to use default options
// ascii is the output encoding and hex the data encoding to use on input to decrypt and output on encrypt
const crypter = new DataCrypter(undefined,undefined,undefined,"ascii","hex");
const key = "test";
const data = "Very Secret Data";
const encrypted_data = await crypter.EncryptData(data,key);
console.log(encrypted_data); // in hex
const decrypted_data = await crypter.DecryptData(encrypted_data,key);
console.log(decrypted_data); // in ascii
if (decrypted_data === data){
console.log("Success!");
}
``crypto.createCipherIv()cipher.getAuthTag()openssl list -cipher-algorithms in your terminal to see availiabe algorithms (this does not mean that they are supported)