@@ -10,7 +10,7 @@ import { createCMSECDSASignature } from "pkijs";
1010
1111import { toArrayBuffer } from "../../helpers/buffer" ;
1212import { buildCertificateChain } from "../aia" ;
13- import { decryptLegacyPbe , installCryptoEngine , isLegacyPbeOid , PKCS12KDF } from "../crypto" ;
13+ import { decryptLegacyPbe , getCrypto , isLegacyPbeOid , PKCS12KDF } from "../crypto" ;
1414import {
1515 OID_CERT_BAG ,
1616 OID_EC_PUBLIC_KEY ,
@@ -24,12 +24,6 @@ import {
2424import type { DigestAlgorithm , KeyType , SignatureAlgorithm , Signer } from "../types" ;
2525import { CertificateChainError , SignerError } from "../types" ;
2626
27- // Install our legacy crypto engine to handle 3DES/RC2 encrypted P12 files
28- installCryptoEngine ( ) ;
29-
30- // Get the crypto engine (now with legacy support)
31- const cryptoEngine = pkijs . getCrypto ( true ) ;
32-
3327/**
3428 * Options for creating a P12Signer.
3529 */
@@ -252,6 +246,8 @@ export class P12Signer implements Signer {
252246 password : string ,
253247 passwordBuffer : ArrayBuffer ,
254248 ) : Promise < CryptoKey > {
249+ const crypto = getCrypto ( ) ;
250+
255251 // oxlint-disable-next-line typescript/no-unsafe-type-assertion
256252 const keyBag = safeBag . bagValue as pkijs . PKCS8ShroudedKeyBag ;
257253 const algorithmId = keyBag . encryptionAlgorithm . algorithmId ;
@@ -300,7 +296,7 @@ export class P12Signer implements Signer {
300296 decryptedKey = toArrayBuffer ( decrypted ) ;
301297 } else {
302298 // Use pkijs/Web Crypto
303- decryptedKey = await cryptoEngine . decryptEncryptedContentInfo ( {
299+ decryptedKey = await crypto . decryptEncryptedContentInfo ( {
304300 encryptedContentInfo : new pkijs . EncryptedContentInfo ( {
305301 contentEncryptionAlgorithm : keyBag . encryptionAlgorithm ,
306302 encryptedContent : keyBag . encryptedData ,
@@ -325,11 +321,13 @@ export class P12Signer implements Signer {
325321 * Import a PrivateKeyInfo into WebCrypto.
326322 */
327323 private static async importPrivateKey ( privateKeyInfo : pkijs . PrivateKeyInfo ) : Promise < CryptoKey > {
324+ const crypto = getCrypto ( ) ;
325+
328326 const algorithmOid = privateKeyInfo . privateKeyAlgorithm . algorithmId ;
329327
330328 // RSA
331329 if ( algorithmOid === OID_RSA_ENCRYPTION ) {
332- return cryptoEngine . importKey (
330+ return crypto . importKey (
333331 "pkcs8" ,
334332 privateKeyInfo . toSchema ( ) . toBER ( false ) ,
335333 { name : "RSASSA-PKCS1-v1_5" , hash : "SHA-256" } ,
@@ -355,7 +353,7 @@ export class P12Signer implements Signer {
355353 }
356354 }
357355
358- return cryptoEngine . importKey (
356+ return crypto . importKey (
359357 "pkcs8" ,
360358 privateKeyInfo . toSchema ( ) . toBER ( false ) ,
361359 { name : "ECDSA" , namedCurve } ,
@@ -413,6 +411,8 @@ export class P12Signer implements Signer {
413411 * @returns The signature bytes
414412 */
415413 async sign ( data : Uint8Array , algorithm : DigestAlgorithm ) : Promise < Uint8Array > {
414+ const crypto = getCrypto ( ) ;
415+
416416 let signAlgorithm : { name : string ; saltLength ?: number ; hash ?: { name : string } } ;
417417
418418 switch ( this . signatureAlgorithm ) {
@@ -429,7 +429,7 @@ export class P12Signer implements Signer {
429429 break ;
430430 }
431431
432- const signature = await cryptoEngine . sign ( signAlgorithm , this . privateKey , new Uint8Array ( data ) ) ;
432+ const signature = await crypto . sign ( signAlgorithm , this . privateKey , new Uint8Array ( data ) ) ;
433433
434434 // WebCrypto ECDSA returns P1363 format (r || s), but CMS requires DER format
435435 if ( this . signatureAlgorithm === "ECDSA" ) {
0 commit comments