node-opcua-crypto 4.12.0 → 4.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,7 +6,7 @@ import {
6
6
  privateKeyToPEM,
7
7
  removeTrailingLF,
8
8
  toPem
9
- } from "./chunk-LHUQUHQQ.mjs";
9
+ } from "./chunk-F5EAPW2U.mjs";
10
10
 
11
11
  // source_nodejs/read.ts
12
12
  import assert from "assert";
@@ -39,7 +39,7 @@ function readPublicKey(filename) {
39
39
  }
40
40
  function myCreatePrivateKey(rawKey) {
41
41
  if (!createPrivateKey || process.env.NO_CREATE_PRIVATEKEY) {
42
- if (rawKey instanceof Buffer) {
42
+ if (Buffer.isBuffer(rawKey)) {
43
43
  const pemKey = toPem(rawKey, "PRIVATE KEY");
44
44
  assert(["RSA PRIVATE KEY", "PRIVATE KEY"].indexOf(identifyPemType(pemKey)) >= 0);
45
45
  return { hidden: pemKey };
@@ -138,7 +138,7 @@ async function generatePrivateKeyFile(privateKeyFilename, modulusLength) {
138
138
  const privateKeyPem = await privateKeyToPEM(keys.privateKey);
139
139
  await fs4.promises.writeFile(privateKeyFilename, privateKeyPem.privPem, "utf-8");
140
140
  privateKeyPem.privPem = "";
141
- privateKeyPem.privDer = new Uint8Array(0);
141
+ privateKeyPem.privDer = new ArrayBuffer(0);
142
142
  }
143
143
  async function generatePrivateKeyFileAlternate(privateKeyFilename, modulusLength) {
144
144
  const kp = jsrsasign.KEYUTIL.generateKeypair("RSA", modulusLength);
@@ -164,4 +164,4 @@ export {
164
164
  generatePrivateKeyFile,
165
165
  generatePrivateKeyFileAlternate
166
166
  };
167
- //# sourceMappingURL=chunk-AXAFLVME.mjs.map
167
+ //# sourceMappingURL=chunk-XPM4YIBT.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../source_nodejs/read.ts","../source_nodejs/read_certificate_revocation_list.ts","../source_nodejs/read_certificate_signing_request.ts","../source_nodejs/generate_private_key_filename.ts"],"sourcesContent":["// ---------------------------------------------------------------------------------------------------------------------\n// node-opcua-crypto\n// ---------------------------------------------------------------------------------------------------------------------\n// Copyright (c) 2014-2022 - Etienne Rossignon - etienne.rossignon (at) gadz.org\n// Copyright (c) 2022-2024 - Sterfive.com\n// ---------------------------------------------------------------------------------------------------------------------\n//\n// This project is licensed under the terms of the MIT license.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated\n// documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the\n// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to\n// permit persons to whom the Software is furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the\n// Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE\n// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\n// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n// ---------------------------------------------------------------------------------------------------------------------\n\nimport assert from \"assert\";\nimport fs from \"node:fs\";\nimport path from \"node:path\";\nimport { createPrivateKey, createPublicKey } from \"crypto\";\nimport { Certificate, CertificatePEM, DER, PEM, PublicKey, PublicKeyPEM, PrivateKeyPEM, PrivateKey } from \"../source/common.js\";\nimport { convertPEMtoDER, identifyPemType, removeTrailingLF, toPem } from \"../source/crypto_utils.js\";\nimport sshpk from \"sshpk\";\n\nfunction _readPemFile(filename: string): PEM {\n assert(typeof filename === \"string\");\n return removeTrailingLF(fs.readFileSync(filename, \"utf-8\"));\n}\n\nfunction _readPemOrDerFileAsDER(filename: string): DER {\n if (filename.match(/.*\\.der/)) {\n return fs.readFileSync(filename) as Buffer;\n }\n const raw_key: string = _readPemFile(filename);\n return convertPEMtoDER(raw_key);\n}\n\n/**\n * read a DER or PEM certificate from file\n */\nexport function readCertificate(filename: string): Certificate {\n return _readPemOrDerFileAsDER(filename) as Certificate;\n}\n\n/**\n * read a DER or PEM certificate from file\n */\nexport function readPublicKey(filename: string): PublicKey {\n if (filename.match(/.*\\.der/)) {\n const der = fs.readFileSync(filename) as Buffer;\n return createPublicKey(der);\n } else {\n const raw_key: string = _readPemFile(filename);\n return createPublicKey(raw_key);\n }\n}\n\n// console.log(\"createPrivateKey\", (crypto as any).createPrivateKey, process.env.NO_CREATE_PRIVATEKEY);\n\nfunction myCreatePrivateKey(rawKey: string | Buffer): PrivateKey {\n if (!createPrivateKey || process.env.NO_CREATE_PRIVATEKEY) {\n // we are not running nodejs or createPrivateKey is not supported in the environment\n if (Buffer.isBuffer(rawKey)) {\n const pemKey = toPem(rawKey, \"PRIVATE KEY\");\n assert([\"RSA PRIVATE KEY\", \"PRIVATE KEY\"].indexOf(identifyPemType(pemKey) as string) >= 0);\n return { hidden: pemKey };\n }\n return { hidden: ensureTrailingLF(rawKey as string) };\n }\n // see https://askubuntu.com/questions/1409458/openssl-config-cuases-error-in-node-js-crypto-how-should-the-config-be-updated\n const backup = process.env.OPENSSL_CONF;\n process.env.OPENSSL_CONF = \"/dev/null\";\n const retValue = createPrivateKey(rawKey);\n process.env.OPENSSL_CONF = backup;\n return { hidden: retValue };\n}\n\nfunction ensureTrailingLF(str: string): string {\n return str.match(/\\n$/) ? str : str + \"\\n\";\n}\n/**\n * read a DER or PEM certificate from file\n */\nexport function readPrivateKey(filename: string): PrivateKey {\n if (filename.match(/.*\\.der/)) {\n const der: Buffer = fs.readFileSync(filename);\n return myCreatePrivateKey(der);\n } else {\n const raw_key: string = _readPemFile(filename);\n return myCreatePrivateKey(raw_key);\n }\n}\n\nexport function readCertificatePEM(filename: string): CertificatePEM {\n return _readPemFile(filename);\n}\n\nexport function readPublicKeyPEM(filename: string): PublicKeyPEM {\n return _readPemFile(filename);\n}\n/**\n *\n * @deprecated\n */\nexport function readPrivateKeyPEM(filename: string): PrivateKeyPEM {\n return _readPemFile(filename);\n}\n\nlet _g_certificate_store: string = \"\";\n\nexport function setCertificateStore(store: string): string {\n const old_store = _g_certificate_store;\n _g_certificate_store = store;\n return old_store;\n}\nexport function getCertificateStore(): string {\n if (!_g_certificate_store) {\n _g_certificate_store = path.join(__dirname, \"../../certificates/\");\n }\n return _g_certificate_store;\n}\n/**\n *\n * @param filename\n */\nexport function readPrivateRsaKey(filename: string): PrivateKey {\n if (!createPrivateKey) {\n throw new Error(\"createPrivateKey is not supported in this environment\");\n }\n if (filename.substring(0, 1) !== \".\" && !fs.existsSync(filename)) {\n filename = path.join(getCertificateStore(), filename);\n }\n const content = fs.readFileSync(filename, \"utf8\");\n const sshKey = sshpk.parsePrivateKey(content, \"auto\");\n const key = sshKey.toString(\"pkcs1\") as PEM;\n const hidden = createPrivateKey({ format: \"pem\", type: \"pkcs1\", key });\n return { hidden };\n}\n\nexport function readPublicRsaKey(filename: string): PublicKey {\n if (filename.substring(0, 1) !== \".\" && !fs.existsSync(filename)) {\n filename = path.join(getCertificateStore(), filename);\n }\n const content = fs.readFileSync(filename, \"utf-8\");\n const sshKey = sshpk.parseKey(content, \"ssh\");\n const key = sshKey.toString(\"pkcs1\") as PEM;\n return createPublicKey({ format: \"pem\", type: \"pkcs1\", key });\n}\n","// ---------------------------------------------------------------------------------------------------------------------\n// node-opcua-crypto\n// ---------------------------------------------------------------------------------------------------------------------\n// Copyright (c) 2014-2022 - Etienne Rossignon - etienne.rossignon (at) gadz.org\n// Copyright (c) 2022-2024 - Sterfive.com\n// ---------------------------------------------------------------------------------------------------------------------\n//\n// This project is licensed under the terms of the MIT license.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated\n// documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the\n// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to\n// permit persons to whom the Software is furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the\n// Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE\n// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\n// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n// ---------------------------------------------------------------------------------------------------------------------\n\nimport fs from \"node:fs\";\nimport { convertPEMtoDER } from \"../source/crypto_utils.js\";\nimport { CertificateRevocationList } from \"../source/common.js\";\n\nexport async function readCertificateRevocationList(filename: string): Promise<CertificateRevocationList> {\n const crl = await fs.promises.readFile(filename);\n if (crl[0] === 0x30 && crl[1] === 0x82) {\n // der format\n return crl as CertificateRevocationList;\n }\n const raw_crl = crl.toString();\n return convertPEMtoDER(raw_crl);\n}\n","// ---------------------------------------------------------------------------------------------------------------------\n// node-opcua-crypto\n// ---------------------------------------------------------------------------------------------------------------------\n// Copyright (c) 2014-2022 - Etienne Rossignon - etienne.rossignon (at) gadz.org\n// Copyright (c) 2022-2024 - Sterfive.com\n// ---------------------------------------------------------------------------------------------------------------------\n//\n// This project is licensed under the terms of the MIT license.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated\n// documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the\n// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to\n// permit persons to whom the Software is furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the\n// Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE\n// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\n// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n// ---------------------------------------------------------------------------------------------------------------------\n\nimport fs from \"node:fs\";\nimport { convertPEMtoDER } from \"../source/crypto_utils.js\";\nimport { CertificateRevocationList } from \"../source/common.js\";\n\nexport type CertificateSigningRequest = Buffer;\n\nexport async function readCertificateSigningRequest(filename: string): Promise<CertificateSigningRequest> {\n const csr = await fs.promises.readFile(filename);\n if (csr[0] === 0x30 && csr[1] === 0x82) {\n // der format\n return csr as CertificateRevocationList;\n }\n const raw_crl = csr.toString();\n return convertPEMtoDER(raw_crl);\n}\n","// ---------------------------------------------------------------------------------------------------------------------\n// node-opcua-crypto\n// ---------------------------------------------------------------------------------------------------------------------\n// Copyright (c) 2014-2022 - Etienne Rossignon - etienne.rossignon (at) gadz.org\n// Copyright (c) 2022-2024 - Sterfive.com\n// ---------------------------------------------------------------------------------------------------------------------\n//\n// This project is licensed under the terms of the MIT license.\n//\n// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated\n// documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the\n// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to\n// permit persons to whom the Software is furnished to do so, subject to the following conditions:\n//\n// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the\n// Software.\n//\n// THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE\n// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\n// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR\n// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n// ---------------------------------------------------------------------------------------------------------------------\n\nimport fs from \"node:fs\";\nimport { generateKeyPair, privateKeyToPEM } from \"../source/index.js\";\nimport jsrsasign from \"jsrsasign\";\nexport async function generatePrivateKeyFile(privateKeyFilename: string, modulusLength: 1024 | 2048 | 3072 | 4096) {\n const keys = await generateKeyPair(modulusLength);\n const privateKeyPem = await privateKeyToPEM(keys.privateKey);\n await fs.promises.writeFile(privateKeyFilename, privateKeyPem.privPem, \"utf-8\");\n privateKeyPem.privPem = \"\";\n privateKeyPem.privDer = new ArrayBuffer(0);\n}\n\n/**\n * alternate function to generate PrivateKeyFile, using jsrsasign.\n *\n * This function is slower than generatePrivateKeyFile\n */\nexport async function generatePrivateKeyFileAlternate(privateKeyFilename: string, modulusLength: 2048 | 3072 | 4096) {\n const kp = jsrsasign.KEYUTIL.generateKeypair(\"RSA\", modulusLength);\n const prv = kp.prvKeyObj;\n const pub = kp.pubKeyObj;\n const prvpem = jsrsasign.KEYUTIL.getPEM(prv, \"PKCS8PRV\");\n // const pubpem = jsrsasign.KEYUTIL.getPEM(pub, \"PKCS8PUB\");\n await fs.promises.writeFile(privateKeyFilename, prvpem, \"utf-8\");\n}\n"],"mappings":";;;;;;;;;;;AAuBA,OAAO,YAAY;AACnB,OAAO,QAAQ;AACf,OAAO,UAAU;AACjB,SAAS,kBAAkB,uBAAuB;AAGlD,OAAO,WAAW;AAElB,SAAS,aAAa,UAAuB;A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__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
 
30
30
  // index.ts
31
- var node_opcua_crypto_exports = {};
32
- __export(node_opcua_crypto_exports, {
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
33
  CertificatePurpose: () => CertificatePurpose,
34
34
  PaddingAlgorithm: () => PaddingAlgorithm,
35
35
  RSA_PKCS1_OAEP_PADDING: () => RSA_PKCS1_OAEP_PADDING,
@@ -117,7 +117,7 @@ __export(node_opcua_crypto_exports, {
117
117
  verifyChunkSignatureWithDerivedKeys: () => verifyChunkSignatureWithDerivedKeys,
118
118
  verifyMessageChunkSignature: () => verifyMessageChunkSignature
119
119
  });
120
- module.exports = __toCommonJS(node_opcua_crypto_exports);
120
+ module.exports = __toCommonJS(index_exports);
121
121
 
122
122
  // source/asn1.ts
123
123
  var import_assert = __toESM(require("assert"));
@@ -1051,7 +1051,7 @@ function readTbsCertificate(buffer, block) {
1051
1051
  };
1052
1052
  }
1053
1053
  function exploreCertificate(certificate) {
1054
- (0, import_assert3.default)(certificate instanceof Buffer);
1054
+ (0, import_assert3.default)(Buffer.isBuffer(certificate));
1055
1055
  if (!certificate._exploreCertificate_cache) {
1056
1056
  const block_info = readTag(certificate, 0);
1057
1057
  const blocks = readStruct(certificate, block_info);
@@ -1094,7 +1094,7 @@ var { hexy } = import_hexy.default;
1094
1094
  var PEM_REGEX = /^(-----BEGIN (.*)-----\r?\n([/+=a-zA-Z0-9\r\n]*)\r?\n-----END \2-----\r?\n?)/gm;
1095
1095
  var PEM_TYPE_REGEX = /^(-----BEGIN (.*)-----)/m;
1096
1096
  function identifyPemType(rawKey) {
1097
- if (rawKey instanceof Buffer) {
1097
+ if (Buffer.isBuffer(rawKey)) {
1098
1098
  rawKey = rawKey.toString("utf8");
1099
1099
  }
1100
1100
  const match = PEM_TYPE_REGEX.exec(rawKey);
@@ -1109,7 +1109,7 @@ function toPem(raw_key, pem) {
1109
1109
  (0, import_assert4.default)(typeof pem === "string");
1110
1110
  let pemType = identifyPemType(raw_key);
1111
1111
  if (pemType) {
1112
- return raw_key instanceof Buffer ? removeTrailingLF(raw_key.toString("utf8")) : removeTrailingLF(raw_key);
1112
+ return Buffer.isBuffer(raw_key) ? removeTrailingLF(raw_key.toString("utf8")) : removeTrailingLF(raw_key);
1113
1113
  } else {
1114
1114
  pemType = pem;
1115
1115
  (0, import_assert4.default)(["CERTIFICATE REQUEST", "CERTIFICATE", "RSA PRIVATE KEY", "PUBLIC KEY", "X509 CRL"].indexOf(pemType) >= 0);
@@ -1245,7 +1245,7 @@ function privateDecrypt_long(buffer, privateKey, blockSize, paddingAlgorithm) {
1245
1245
  return outputBuffer.subarray(0, total_length);
1246
1246
  }
1247
1247
  function coerceCertificatePem(certificate) {
1248
- if (certificate instanceof Buffer) {
1248
+ if (Buffer.isBuffer(certificate)) {
1249
1249
  certificate = toPem(certificate, "CERTIFICATE");
1250
1250
  }
1251
1251
  (0, import_assert4.default)(typeof certificate === "string");
@@ -1456,7 +1456,7 @@ function coerceCertificate(certificate) {
1456
1456
  if (typeof certificate === "string") {
1457
1457
  certificate = convertPEMtoDER(certificate);
1458
1458
  }
1459
- (0, import_assert6.default)(certificate instanceof Buffer);
1459
+ (0, import_assert6.default)(Buffer.isBuffer(certificate));
1460
1460
  return certificate;
1461
1461
  }
1462
1462
  function exploreCertificateInfo(certificate) {
@@ -1483,7 +1483,7 @@ function plus(buf1, buf2) {
1483
1483
  return Buffer.concat([buf1, buf2]);
1484
1484
  }
1485
1485
  function makePseudoRandomBuffer(secret, seed, minLength, sha1or256) {
1486
- (0, import_assert7.default)(seed instanceof Buffer);
1486
+ (0, import_assert7.default)(Buffer.isBuffer(seed));
1487
1487
  (0, import_assert7.default)(sha1or256 === "SHA1" || sha1or256 === "SHA256");
1488
1488
  const a = [];
1489
1489
  a[0] = seed;
@@ -1527,7 +1527,7 @@ function removePadding(buffer) {
1527
1527
  return reduceLength(buffer, nbPaddingBytes);
1528
1528
  }
1529
1529
  function verifyChunkSignature(chunk, options) {
1530
- (0, import_assert7.default)(chunk instanceof Buffer);
1530
+ (0, import_assert7.default)(Buffer.isBuffer(chunk));
1531
1531
  let signatureLength = options.signatureLength || 0;
1532
1532
  if (signatureLength === 0) {
1533
1533
  const cert = exploreCertificateInfo(options.publicKey);
@@ -1573,8 +1573,8 @@ function decryptBufferWithDerivedKeys(buffer, derivedKeys) {
1573
1573
  return Buffer.concat(decrypted_chunks);
1574
1574
  }
1575
1575
  function makeMessageChunkSignatureWithDerivedKeys(message, derivedKeys) {
1576
- (0, import_assert7.default)(message instanceof Buffer);
1577
- (0, import_assert7.default)(derivedKeys.signingKey instanceof Buffer);
1576
+ (0, import_assert7.default)(Buffer.isBuffer(message));
1577
+ (0, import_assert7.default)(Buffer.isBuffer(derivedKeys.signingKey));
1578
1578
  (0, import_assert7.default)(typeof derivedKeys.sha1or256 === "string");
1579
1579
  (0, import_assert7.default)(derivedKeys.sha1or256 === "SHA1" || derivedKeys.sha1or256 === "SHA256");
1580
1580
  const signature = (0, import_crypto3.createHmac)(derivedKeys.sha1or256, derivedKeys.signingKey).update(message).digest();
@@ -1962,7 +1962,7 @@ function coercePEMorDerToPrivateKey(privateKeyInDerOrPem) {
1962
1962
  }
1963
1963
  async function _coercePrivateKey(privateKey) {
1964
1964
  const KeyObject4 = crypto2.KeyObject;
1965
- if (privateKey instanceof Buffer) {
1965
+ if (Buffer.isBuffer(privateKey)) {
1966
1966
  const privateKey1 = await derToPrivateKey(privateKey);
1967
1967
  return KeyObject4.from(privateKey1);
1968
1968
  } else if (typeof privateKey === "string") {
@@ -6278,7 +6278,7 @@ function readPublicKey(filename) {
6278
6278
  }
6279
6279
  function myCreatePrivateKey(rawKey) {
6280
6280
  if (!import_crypto13.createPrivateKey || process.env.NO_CREATE_PRIVATEKEY) {
6281
- if (rawKey instanceof Buffer) {
6281
+ if (Buffer.isBuffer(rawKey)) {
6282
6282
  const pemKey = toPem(rawKey, "PRIVATE KEY");
6283
6283
  (0, import_assert8.default)(["RSA PRIVATE KEY", "PRIVATE KEY"].indexOf(identifyPemType(pemKey)) >= 0);
6284
6284
  return { hidden: pemKey };
@@ -6377,7 +6377,7 @@ async function generatePrivateKeyFile(privateKeyFilename, modulusLength) {
6377
6377
  const privateKeyPem = await privateKeyToPEM(keys.privateKey);
6378
6378
  await import_node_fs4.default.promises.writeFile(privateKeyFilename, privateKeyPem.privPem, "utf-8");
6379
6379
  privateKeyPem.privPem = "";
6380
- privateKeyPem.privDer = new Uint8Array(0);
6380
+ privateKeyPem.privDer = new ArrayBuffer(0);
6381
6381
  }
6382
6382
  async function generatePrivateKeyFileAlternate(privateKeyFilename, modulusLength) {
6383
6383
  const kp = import_jsrsasign3.default.KEYUTIL.generateKeypair("RSA", modulusLength);