사소한 리팩토링

This commit is contained in:
static
2024-12-31 06:40:31 +09:00
parent f4b9137214
commit 5034598d0b
3 changed files with 8 additions and 8 deletions

View File

@@ -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"),

View File

@@ -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",

View File

@@ -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;
};