Adding user encryption key
This commit is contained in:
5
src/helper/random.ts
Normal file
5
src/helper/random.ts
Normal 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
14
src/helper/user_key.ts
Normal 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))
|
||||
}
|
Reference in New Issue
Block a user