21 lines
541 B
JavaScript
21 lines
541 B
JavaScript
|
import { crypto, cipher, cipheriv, decipher, decipheriv } from '../src/index.js'
|
||
|
|
||
|
let algorithm = 'aes-128-cbc'
|
||
|
let data = 'abcd'
|
||
|
let key = Buffer.alloc(16)
|
||
|
let key2 = Buffer.alloc(32)
|
||
|
let iv = Buffer.alloc(16)
|
||
|
|
||
|
let encode = 'base64'
|
||
|
|
||
|
// console.log(crypto.getCiphers())
|
||
|
|
||
|
let output1 = cipher(algorithm, data, key, 'utf8', encode)
|
||
|
let output2 = cipheriv(algorithm, data, key, iv)
|
||
|
|
||
|
console.log(output1)
|
||
|
console.log(output2.toString(encode))
|
||
|
|
||
|
console.log(decipher(algorithm, output1, key))
|
||
|
console.log(decipheriv(algorithm, output2, key, iv))
|