Skip to content

Commit

Permalink
cleanup private key pem
Browse files Browse the repository at this point in the history
  • Loading branch information
erossignon committed Jul 24, 2023
1 parent 9412ce1 commit 02daf53
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion source/crypto_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion source/crypto_utils2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" });
Expand Down
2 changes: 1 addition & 1 deletion source_nodejs/read.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
}
Expand Down

0 comments on commit 02daf53

Please sign in to comment.