Compare commits
No commits in common. "e470b68ea57a85a3287afd67995c12cc3c5698aa" and "6fd21e4e36166468f5de25baa4ca57bbb02de284" have entirely different histories.
e470b68ea5
...
6fd21e4e36
6
index.js
6
index.js
@ -165,7 +165,7 @@ function encrypt_aes (text, pass, mode = encryption_mode_cbc_256) {
|
|||||||
const salt = crypto.randomBytes (mode.salt_size);
|
const salt = crypto.randomBytes (mode.salt_size);
|
||||||
// eslint-disable-next-line no-sync
|
// eslint-disable-next-line no-sync
|
||||||
const key = crypto.pbkdf2Sync (
|
const key = crypto.pbkdf2Sync (
|
||||||
Buffer.from (pass),
|
Buffer.from (pass, 'utf-8'),
|
||||||
salt,
|
salt,
|
||||||
mode.iterations,
|
mode.iterations,
|
||||||
mode.key_size,
|
mode.key_size,
|
||||||
@ -203,7 +203,7 @@ function decrypt_aes (
|
|||||||
buf = buf.slice (mode.salt_size);
|
buf = buf.slice (mode.salt_size);
|
||||||
// eslint-disable-next-line no-sync
|
// eslint-disable-next-line no-sync
|
||||||
const key = crypto.pbkdf2Sync (
|
const key = crypto.pbkdf2Sync (
|
||||||
Buffer.from (pass),
|
Buffer.from (pass, 'utf-8'),
|
||||||
salt,
|
salt,
|
||||||
mode.iterations,
|
mode.iterations,
|
||||||
mode.key_size,
|
mode.key_size,
|
||||||
@ -216,7 +216,7 @@ function decrypt_aes (
|
|||||||
cipher.update (buf),
|
cipher.update (buf),
|
||||||
cipher.final ()
|
cipher.final ()
|
||||||
])
|
])
|
||||||
.toString ();
|
.toString ('utf-8');
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
if (rethrow)
|
if (rethrow)
|
||||||
|
@ -16,29 +16,6 @@ test ('decryption', (t) => {
|
|||||||
t.is (dec, 'foo');
|
t.is (dec, 'foo');
|
||||||
});
|
});
|
||||||
|
|
||||||
test ('encryption 128', (t) => {
|
|
||||||
const enc = crypto.encrypt_aes (
|
|
||||||
'foo',
|
|
||||||
'bar',
|
|
||||||
crypto.encryption_mode_cbc_128,
|
|
||||||
);
|
|
||||||
t.is (typeof enc, 'string');
|
|
||||||
});
|
|
||||||
|
|
||||||
test ('decryption 128', (t) => {
|
|
||||||
const enc = crypto.encrypt_aes (
|
|
||||||
'foo',
|
|
||||||
'bar',
|
|
||||||
crypto.encryption_mode_cbc_128,
|
|
||||||
);
|
|
||||||
const dec = crypto.decrypt_aes (
|
|
||||||
enc,
|
|
||||||
'bar',
|
|
||||||
crypto.encryption_mode_cbc_128,
|
|
||||||
);
|
|
||||||
t.is (dec, 'foo');
|
|
||||||
});
|
|
||||||
|
|
||||||
test ('fail decryption', (t) => {
|
test ('fail decryption', (t) => {
|
||||||
const enc = crypto.encrypt_aes ('foo', 'bar');
|
const enc = crypto.encrypt_aes ('foo', 'bar');
|
||||||
const dec = crypto.decrypt_aes (enc, 'baz');
|
const dec = crypto.decrypt_aes (enc, 'baz');
|
||||||
|
@ -23,10 +23,7 @@ test ('random_hex with default length', (t) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test ('random_hex should refuse lenght smaller 1', (t) => {
|
test ('random_hex should refuse lenght smaller 1', (t) => {
|
||||||
const error = t.throws (
|
t.throws (() => (crypto.random_hex (0)));
|
||||||
() => (crypto.random_hex (0))
|
|
||||||
);
|
|
||||||
t.is(error.message, 'invalid length');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test ('random_string', (t) => {
|
test ('random_string', (t) => {
|
||||||
@ -40,10 +37,7 @@ test ('random_string with default length', (t) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
test ('random_string should refuse lenght smaller 1', (t) => {
|
test ('random_string should refuse lenght smaller 1', (t) => {
|
||||||
const error = t.throws (
|
t.throws (() => (crypto.random_string (0)));
|
||||||
() => (crypto.random_string (0))
|
|
||||||
);
|
|
||||||
t.is(error.message, 'invalid length');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test ('hash_sha512', (t) => {
|
test ('hash_sha512', (t) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user