mirror of
https://github.com/remotely-save/remotely-save.git
synced 2024-06-07 21:10:45 +00:00
use hash-wasm
This commit is contained in:
parent
6431182ec3
commit
bcf8586fbf
@ -38,6 +38,7 @@
|
||||
"crypto-browserify": "^3.12.0",
|
||||
"domain-browser": "^4.22.0",
|
||||
"events": "^3.3.0",
|
||||
"hash-wasm": "^4.9.0",
|
||||
"hi-base32": "^0.5.1",
|
||||
"https-browserify": "^1.0.0",
|
||||
"lovefield-ts": "^0.7.0",
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { randomBytes, pbkdf2, createDecipheriv, createCipheriv } from "crypto";
|
||||
import { randomBytes, createDecipheriv, createCipheriv } from "crypto";
|
||||
import { pbkdf2, createSHA256 } from "hash-wasm";
|
||||
import { promisify } from "util";
|
||||
import * as base32 from "hi-base32";
|
||||
import { bufferToArrayBuffer, arrayBufferToBuffer } from "./misc";
|
||||
@ -11,13 +12,14 @@ export const encryptBuffer = async (
|
||||
rounds: number = DEFAULT_ITER
|
||||
) => {
|
||||
const salt = await promisify(randomBytes)(8);
|
||||
const derivedKey = await promisify(pbkdf2)(
|
||||
password,
|
||||
salt,
|
||||
rounds,
|
||||
32 + 16,
|
||||
"sha256"
|
||||
);
|
||||
const derivedKey = await pbkdf2({
|
||||
password: password,
|
||||
salt: salt,
|
||||
iterations: rounds,
|
||||
hashLength: 32 + 16,
|
||||
hashFunction: createSHA256(),
|
||||
outputType: "binary",
|
||||
});
|
||||
const key = derivedKey.slice(0, 32);
|
||||
const iv = derivedKey.slice(32, 32 + 16);
|
||||
const cipher = createCipheriv("aes-256-cbc", key, iv);
|
||||
@ -35,13 +37,14 @@ export const decryptBuffer = async (
|
||||
) => {
|
||||
const prefix = buf.slice(0, 8);
|
||||
const salt = buf.slice(8, 16);
|
||||
const derivedKey = await promisify(pbkdf2)(
|
||||
password,
|
||||
salt,
|
||||
rounds,
|
||||
32 + 16,
|
||||
"sha256"
|
||||
);
|
||||
const derivedKey = await pbkdf2({
|
||||
password: password,
|
||||
salt: salt,
|
||||
iterations: rounds,
|
||||
hashLength: 32 + 16,
|
||||
hashFunction: createSHA256(),
|
||||
outputType: "binary",
|
||||
});
|
||||
const key = derivedKey.slice(0, 32);
|
||||
const iv = derivedKey.slice(32, 32 + 16);
|
||||
const decipher = createDecipheriv("aes-256-cbc", key, iv);
|
||||
|
Loading…
Reference in New Issue
Block a user