CREDENTIAL TYPE MANAGEMENT WORKS
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import Password from "../tools/Password";
|
||||
import crypto from "crypto";
|
||||
import { secureValuesPublicKey } from "../../constants";
|
||||
|
||||
export const generateSecureValue = (content: string) => {
|
||||
// Generate a hash of the content
|
||||
const hash = Password.hash(content);
|
||||
|
||||
// Encrypt the content using the .secureValues.pub public key
|
||||
const encrypted = crypto.publicEncrypt(
|
||||
{
|
||||
key: secureValuesPublicKey,
|
||||
padding: crypto.constants.RSA_PKCS1_OAEP_PADDING,
|
||||
oaepHash: "sha256",
|
||||
},
|
||||
Buffer.from(content, "utf-8"),
|
||||
);
|
||||
|
||||
// Return the encrypted content and the hash for storage
|
||||
return {
|
||||
encrypted: encrypted.toString("base64"),
|
||||
hash,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user