mirror of
https://github.com/kmc7468/arkvault.git
synced 2025-12-12 21:08:46 +00:00
사소한 리팩토링
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
import { constants, randomBytes, createPublicKey, publicEncrypt, verify } from "crypto";
|
||||
import { promisify } from "util";
|
||||
|
||||
const makePubKeyPem = (pubKey: string) =>
|
||||
const makePubKeyToPem = (pubKey: string) =>
|
||||
`-----BEGIN PUBLIC KEY-----\n${pubKey}\n-----END PUBLIC KEY-----`;
|
||||
|
||||
export const verifyPubKey = (pubKey: string) => {
|
||||
const pubKeyPem = makePubKeyPem(pubKey);
|
||||
const pubKeyPem = makePubKeyToPem(pubKey);
|
||||
const pubKeyObject = createPublicKey(pubKeyPem);
|
||||
return (
|
||||
pubKeyObject.asymmetricKeyType === "rsa" &&
|
||||
@@ -14,7 +14,7 @@ export const verifyPubKey = (pubKey: string) => {
|
||||
};
|
||||
|
||||
export const encryptAsymmetric = (data: Buffer, encPubKey: string) => {
|
||||
return publicEncrypt({ key: makePubKeyPem(encPubKey), oaepHash: "sha256" }, data);
|
||||
return publicEncrypt({ key: makePubKeyToPem(encPubKey), oaepHash: "sha256" }, data);
|
||||
};
|
||||
|
||||
export const verifySignature = (data: string, signature: string, sigPubKey: string) => {
|
||||
@@ -22,7 +22,7 @@ export const verifySignature = (data: string, signature: string, sigPubKey: stri
|
||||
"rsa-sha256",
|
||||
Buffer.from(data, "base64"),
|
||||
{
|
||||
key: makePubKeyPem(sigPubKey),
|
||||
key: makePubKeyToPem(sigPubKey),
|
||||
padding: constants.RSA_PKCS1_PSS_PADDING,
|
||||
},
|
||||
Buffer.from(signature, "base64"),
|
||||
|
||||
@@ -25,8 +25,8 @@
|
||||
const clientKeysExported = exportClientKeys(
|
||||
data.encryptKeyBase64,
|
||||
data.decryptKeyBase64,
|
||||
data.verifyKeyBase64,
|
||||
data.signKeyBase64,
|
||||
data.verifyKeyBase64,
|
||||
);
|
||||
const clientKeysBlob = new Blob([JSON.stringify(clientKeysExported)], {
|
||||
type: "application/json",
|
||||
|
||||
@@ -13,15 +13,15 @@ type ExportedKeyPairs = {
|
||||
version: 1;
|
||||
encryptKey: string;
|
||||
decryptKey: string;
|
||||
verifyKey: string;
|
||||
signKey: string;
|
||||
verifyKey: string;
|
||||
};
|
||||
|
||||
export const exportClientKeys = (
|
||||
encryptKeyBase64: string,
|
||||
decryptKeyBase64: string,
|
||||
verifyKeyBase64: string,
|
||||
signKeyBase64: string,
|
||||
verifyKeyBase64: string,
|
||||
) => {
|
||||
return {
|
||||
version: 1,
|
||||
@@ -29,8 +29,8 @@ export const exportClientKeys = (
|
||||
exportedAt: new Date(),
|
||||
encryptKey: encryptKeyBase64,
|
||||
decryptKey: decryptKeyBase64,
|
||||
verifyKey: verifyKeyBase64,
|
||||
signKey: signKeyBase64,
|
||||
verifyKey: verifyKeyBase64,
|
||||
} satisfies ExportedKeyPairs;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user