OpenAuth_server/src/helper/user_key.ts

19 lines
496 B
TypeScript
Raw Normal View History

2019-01-21 10:24:20 +00:00
// import * as crypto from "crypto-js"
import { IUser } from "../models/user";
import { IClient } from "../models/client";
2020-08-07 14:16:39 +00:00
import * as crypto from "crypto";
2019-01-21 10:24:20 +00:00
function sha512(text: string) {
2020-08-07 14:16:39 +00:00
let hash = crypto.createHash("sha512");
hash.update(text);
return hash.digest("base64");
2019-01-21 10:24:20 +00:00
}
export function getEncryptionKey(user: IUser, client: IClient) {
2020-08-07 14:16:39 +00:00
return sha512(
sha512(user.encryption_key) +
sha512(client._id.toHexString()) +
sha512(client.client_id)
);
}