@@ -5,6 +5,8 @@ import { SOURCEBOT_ENCRYPTION_KEY } from './environment';
55const algorithm = 'aes-256-cbc' ;
66const ivLength = 16 ; // 16 bytes for CBC
77
8+ const publicKeyCache = new Map < string , string > ( ) ;
9+
810const generateIV = ( ) : Buffer => {
911 return crypto . randomBytes ( ivLength ) ;
1012} ;
@@ -67,12 +69,17 @@ export function decrypt(iv: string, encryptedText: string): string {
6769
6870export function verifySignature ( data : string , signature : string , publicKeyPath : string ) : boolean {
6971 try {
70- if ( ! fs . existsSync ( publicKeyPath ) ) {
71- throw new Error ( `Public key file not found at: ${ publicKeyPath } ` ) ;
72+ let publicKey = publicKeyCache . get ( publicKeyPath ) ;
73+
74+ if ( ! publicKey ) {
75+ if ( ! fs . existsSync ( publicKeyPath ) ) {
76+ throw new Error ( `Public key file not found at: ${ publicKeyPath } ` ) ;
77+ }
78+
79+ publicKey = fs . readFileSync ( publicKeyPath , 'utf8' ) ;
80+ publicKeyCache . set ( publicKeyPath , publicKey ) ;
7281 }
7382
74- const publicKey = fs . readFileSync ( publicKeyPath , 'utf8' ) ;
75-
7683 const base64Signature = signature . replace ( / - / g, '+' ) . replace ( / _ / g, '/' ) ;
7784 const paddedSignature = base64Signature + '=' . repeat ( ( 4 - base64Signature . length % 4 ) % 4 ) ;
7885 const signatureBuffer = Buffer . from ( paddedSignature , 'base64' ) ;
0 commit comments