blocktrail-sdk
Version:
BlockTrail's Developer Friendly API binding for NodeJS
25 lines (20 loc) • 1.12 kB
JavaScript
/**
* AES-GCM exports
*/
function AES_GCM_encrypt_bytes ( data, key, nonce, adata, tagSize ) {
if ( data === undefined ) throw new SyntaxError("data required");
if ( key === undefined ) throw new SyntaxError("key required");
if ( nonce === undefined ) throw new SyntaxError("nonce required");
return new AES_GCM( { heap: _AES_heap_instance, asm: _AES_asm_instance, key: key, nonce: nonce, adata: adata, tagSize: tagSize } ).encrypt(data).result;
}
function AES_GCM_decrypt_bytes ( data, key, nonce, adata, tagSize ) {
if ( data === undefined ) throw new SyntaxError("data required");
if ( key === undefined ) throw new SyntaxError("key required");
if ( nonce === undefined ) throw new SyntaxError("nonce required");
return new AES_GCM( { heap: _AES_heap_instance, asm: _AES_asm_instance, key: key, nonce: nonce, adata: adata, tagSize: tagSize } ).decrypt(data).result;
}
exports.AES_GCM = AES_GCM;
exports.AES_GCM.encrypt = AES_GCM_encrypt_bytes;
exports.AES_GCM.decrypt = AES_GCM_decrypt_bytes;
exports.AES_GCM.Encrypt = AES_GCM_Encrypt;
exports.AES_GCM.Decrypt = AES_GCM_Decrypt;