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