Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

217
Visualizações
signing a CSR with pkijs

I am trying to sign a CSR with a local certificate using pkijs library but CA always returns an error: Failed to parse the PKIOperation request.

I also think sign method in pkijs only returns the signature and not the enveloped data with it as my enveloped data size is quite larger than signed data size.

Here is the code I am using to sign the data:

public signScepCsr(csr: ArrayBuffer, signingCert: Certificate, privateKey: any) {
        let sequence = Promise.resolve();

        //region Create a message digest
        const crypto = getCrypto();

        sequence.then(() => {
            let certSigned = new SignedData({
                version: 1,
                encapContentInfo: new EncapsulatedContentInfo({
                    eContentType: this.envelopedDataOid
                }),
                signerInfos: [new SignerInfo({
                    version: 1,
                    sid: new IssuerAndSerialNumber({
                        issuer: signingCert.issuer,
                        serialNumber: signingCert.serialNumber
                    }),
                    messageType: 19,
                    transactionID: Guid.create().toString(),
                })],
                certificaes: [signingCert]
            });

            // Sign the CSR buffer with local certificate private key.
            return certSigned.sign(privateKey, 0, this.hashAlg, csr);
        });

        let result = '';
        
        return sequence.then((result) => {
            let r2 = result as SignedData;
            let certSignedSchema = r2.toSchema(true);
            let signedContent = new ContentInfo({
                contentType: this.signedDataOid,
                content: certSignedSchema
            });
  
            let finalSignedSchema = signedContent.toSchema();
    
            //region Make length of some elements in "indefinite form"
            finalSignedSchema.lenBlock.isIndefiniteForm = true;
    
            var block1 = finalSignedSchema.valueBlock.value[1];
            block1.lenBlock.isIndefiniteForm = true;
    
            var block2 = block1.valueBlock.value[0];
            block2.lenBlock.isIndefiniteForm = true;
    
            let signedContentBuffer = finalSignedSchema.toBER(false);
            
            let resultStr = window.btoa(String.fromCharCode.apply(null, new Uint8Array(signedContentBuffer)));
            
            return resultStr;
        },
        () => Promise.reject('Failed to successfully sign the CSR.'));
    }

Is there any suggestion?

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda