0
0
mirror of https://github.com/renovatebot/renovate.git synced 2024-12-22 13:38:32 +00:00
renovatebot_renovate/lib/config/decrypt/legacy.ts
renovate[bot] eb8c08079e
chore(deps): update typescript-eslint monorepo to v8 (major) (#30750)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
2024-08-14 10:33:02 +00:00

41 lines
1021 B
TypeScript

/** istanbul ignore file */
import crypto from 'node:crypto';
import { logger } from '../../logger';
export function tryDecryptPublicKeyPKCS1(
privateKey: string,
encryptedStr: string,
): string | null {
let decryptedStr: string | null = null;
try {
decryptedStr = crypto
.privateDecrypt(
{
key: privateKey,
padding: crypto.constants.RSA_PKCS1_PADDING,
},
Buffer.from(encryptedStr, 'base64'),
)
.toString();
} catch {
logger.debug('Could not decrypt using PKCS1 padding');
}
return decryptedStr;
}
export function tryDecryptPublicKeyDefault(
privateKey: string,
encryptedStr: string,
): string | null {
let decryptedStr: string | null = null;
try {
decryptedStr = crypto
.privateDecrypt(privateKey, Buffer.from(encryptedStr, 'base64'))
.toString();
logger.debug('Decrypted config using default padding');
} catch {
logger.debug('Could not decrypt using default padding');
}
return decryptedStr;
}