mirror of
https://github.com/wukko/cobalt.git
synced 2024-11-17 22:00:00 +00:00
crypto: replace base64 with base64url
This commit is contained in:
parent
48ac75b135
commit
73b63e5487
1 changed files with 5 additions and 5 deletions
|
@ -4,14 +4,14 @@ const algorithm = "aes256"
|
||||||
const keyLength = 32;
|
const keyLength = 32;
|
||||||
|
|
||||||
export function generateHmac(str, salt) {
|
export function generateHmac(str, salt) {
|
||||||
return createHmac("sha256", salt).update(str).digest("base64");
|
return createHmac("sha256", salt).update(str).digest("base64url");
|
||||||
}
|
}
|
||||||
|
|
||||||
export function encryptStream(str, iv, secret) {
|
export function encryptStream(str, iv, secret) {
|
||||||
const buff = Buffer.from(JSON.stringify(str), "utf-8");
|
const buff = Buffer.from(JSON.stringify(str), "utf-8");
|
||||||
|
|
||||||
const key = scryptSync(Buffer.from(secret, "base64"), "salt", keyLength);
|
const key = scryptSync(Buffer.from(secret, "base64url"), "salt", keyLength);
|
||||||
const cipher = createCipheriv(algorithm, key, Buffer.from(iv, "base64"));
|
const cipher = createCipheriv(algorithm, key, Buffer.from(iv, "base64url"));
|
||||||
|
|
||||||
return Buffer.concat([ cipher.update(buff), cipher.final() ])
|
return Buffer.concat([ cipher.update(buff), cipher.final() ])
|
||||||
}
|
}
|
||||||
|
@ -19,8 +19,8 @@ export function encryptStream(str, iv, secret) {
|
||||||
export function decryptStream(buf, iv, secret) {
|
export function decryptStream(buf, iv, secret) {
|
||||||
const buff = Buffer.from(buf, "binary");
|
const buff = Buffer.from(buf, "binary");
|
||||||
|
|
||||||
const key = scryptSync(Buffer.from(secret, "base64"), "salt", keyLength);
|
const key = scryptSync(Buffer.from(secret, "base64url"), "salt", keyLength);
|
||||||
const decipher = createDecipheriv(algorithm, key, Buffer.from(iv, "base64"));
|
const decipher = createDecipheriv(algorithm, key, Buffer.from(iv, "base64url"));
|
||||||
|
|
||||||
return Buffer.concat([ decipher.update(buff), decipher.final() ])
|
return Buffer.concat([ decipher.update(buff), decipher.final() ])
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue