18 lines
492 B
TypeScript
18 lines
492 B
TypeScript
"use server";
|
|
import { privateEncrypt } from "crypto";
|
|
import { decryptPrivateKey } from "@/utils/security/decrypt_private_key";
|
|
export async function encryptMessage(message: string) {
|
|
const privateKey = await decryptPrivateKey();
|
|
if (privateKey == null) {
|
|
return null;
|
|
}
|
|
try {
|
|
const message_buffer = Buffer.from(message, "utf-8");
|
|
const message_encrypted = privateEncrypt(privateKey, message_buffer);
|
|
|
|
return message_encrypted;
|
|
} catch (err) {
|
|
throw err;
|
|
}
|
|
}
|