mirror of
https://dev.azure.com/globalhealthx/EMR/_git/helix-engage-server
synced 2026-05-18 20:08:19 +00:00
fix: wrap raw base64 public key with PEM headers for Node crypto
Ozonetel returns raw base64 public key without PEM headers. Node's crypto.publicEncrypt requires PEM format. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -54,10 +54,14 @@ export class OzonetelAdminAuthService implements OnModuleInit {
|
|||||||
return this.login();
|
return this.login();
|
||||||
}
|
}
|
||||||
|
|
||||||
private rsaEncrypt(publicKeyPem: string, plaintext: string): string {
|
private rsaEncrypt(publicKeyRaw: string, plaintext: string): string {
|
||||||
|
// Ozonetel returns raw base64 without PEM headers — wrap it
|
||||||
|
const pem = publicKeyRaw.includes('-----BEGIN')
|
||||||
|
? publicKeyRaw
|
||||||
|
: `-----BEGIN PUBLIC KEY-----\n${publicKeyRaw}\n-----END PUBLIC KEY-----`;
|
||||||
const buffer = Buffer.from(plaintext, 'utf8');
|
const buffer = Buffer.from(plaintext, 'utf8');
|
||||||
const encrypted = publicEncrypt(
|
const encrypted = publicEncrypt(
|
||||||
{ key: publicKeyPem, padding: cryptoConstants.RSA_PKCS1_PADDING },
|
{ key: pem, padding: cryptoConstants.RSA_PKCS1_PADDING },
|
||||||
buffer,
|
buffer,
|
||||||
);
|
);
|
||||||
return encrypted.toString('base64');
|
return encrypted.toString('base64');
|
||||||
|
|||||||
Reference in New Issue
Block a user