Adding user encryption key

This commit is contained in:
Fabian Stamm
2019-01-21 11:24:20 +01:00
parent 26798df304
commit 0612e25882
4 changed files with 58 additions and 2 deletions

5
src/helper/random.ts Normal file
View File

@ -0,0 +1,5 @@
import { randomBytes } from "crypto";
export function randomString(length: number) {
return randomBytes(length).toString("base64").slice(0, length);
}

14
src/helper/user_key.ts Normal file
View File

@ -0,0 +1,14 @@
// import * as crypto from "crypto-js"
import { IUser } from "../models/user";
import { IClient } from "../models/client";
import * as crypto from "crypto"
function sha512(text: string) {
let hash = crypto.createHash("sha512")
hash.update(text)
return hash.digest("base64")
}
export function getEncryptionKey(user: IUser, client: IClient) {
return sha512(sha512(user.encryption_key) + sha512(client._id.toHexString()) + sha512(client.client_id))
}