diff --git a/source/crypto_utils.ts b/source/crypto_utils.ts index d4fb8bf..a53043d 100644 --- a/source/crypto_utils.ts +++ b/source/crypto_utils.ts @@ -69,7 +69,7 @@ export function toPem(raw_key: Buffer | string, pem: string): string { assert(typeof pem === "string"); let pemType = identifyPemType(raw_key); if (pemType) { - return raw_key instanceof Buffer ? raw_key.toString("utf8") : raw_key; + return raw_key instanceof Buffer ? raw_key.toString("utf8").replace(/(\r|\n)+$/gm, "") : raw_key.replace(/(\r|\n)+$/gm, ""); } else { pemType = pem; assert(["CERTIFICATE REQUEST", "CERTIFICATE", "RSA PRIVATE KEY", "PUBLIC KEY", "X509 CRL"].indexOf(pemType) >= 0); diff --git a/source/crypto_utils2.ts b/source/crypto_utils2.ts index 808e230..f56480a 100644 --- a/source/crypto_utils2.ts +++ b/source/crypto_utils2.ts @@ -82,7 +82,7 @@ export function toPem2(raw_key: Buffer | string | KeyObject | PrivateKey, pem: s } export function coercePrivateKeyPem(privateKey: PrivateKey): PrivateKeyPEM { - return toPem2(privateKey, "RSA PRIVATE KEY"); + return toPem2(privateKey, "PRIVATE KEY"); /* if (privateKey.hidden instanceof Buffer) { const o = createPrivateKeyFromNodeJSCrypto({ key: privateKey.hidden, format: "der", type: "pkcs1" }); diff --git a/source_nodejs/read.ts b/source_nodejs/read.ts index 4cf144b..43e0273 100644 --- a/source_nodejs/read.ts +++ b/source_nodejs/read.ts @@ -80,7 +80,7 @@ function myCreatePrivateKey(rawKey: string | Buffer): PrivateKey { if (!createPrivateKey || process.env.NO_CREATE_PRIVATEKEY) { // we are not running nodejs or createPrivateKey is not supported in the environment if (rawKey instanceof Buffer) { - const pemKey = toPem(rawKey, "RSA PRIVATE KEY"); + const pemKey = toPem(rawKey, "PRIVATE KEY"); assert(["RSA PRIVATE KEY", "PRIVATE KEY"].indexOf(identifyPemType(pemKey) as string) >= 0); return { hidden: pemKey }; }