mirror of
https://github.com/renovatebot/renovate.git
synced 2024-12-22 13:38:32 +00:00
eb8c08079e
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
41 lines
1021 B
TypeScript
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;
|
|
}
|