kjur / jsrsasign

The 'jsrsasign' (RSA-Sign JavaScript Library) is an opensource free cryptography library supporting RSA/RSAPSS/ECDSA/DSA signing/validation, ASN.1, PKCS#1/5/8 private/public key, X.509 certificate, CRL, OCSP, CMS SignedData, TimeStamp, CAdES and JSON Web Signature/Token in pure JavaScript.
https://kjur.github.io/jsrsasign
Other
3.25k stars 646 forks source link

The CSR API sample is not working. Throws TypeError: rs.KJUR.asn1.x509.CertificationRequest is not a constructor at Object.<anonymous> #608

Closed robcordes closed 7 months ago

robcordes commented 7 months ago

The code I used to generate the CSR: (version 11 of jsrsasign used)

var rs = require("jsrsasign");

// Generate CSR // signed by private key

var pub = kp.pubKeyObj; var prvpem = rs.KEYUTIL.getPEM(prv, "PKCS8PRV"); var pubpem = rs.KEYUTIL.getPEM(pub, "PKCS8PUB");

csr = new rs.KJUR.asn1.x509.CertificationRequest(); csr.setByParam({ subject: {str:"/C=US/O=Test"}, sbjpubkey: prvpem, //"-----BEGIN PUBLIC KEY...",SA a extreq: [{extname:"subjectAltName",array:[{dns:"example.com"}]}], sigalg: "SHA256withRSA", sbjprvkey: pubpem // "-----BEGIN PRIVATE KEY..." }); pem = csr.getPEM(); // signed with sbjprvkey automatically

robcordes commented 7 months ago

the version of JSRSASIGHN used is version 11.

robcordes commented 7 months ago

I somehow got the wrong sample code. The below code works.

var rs = require("jsrsasign");

try { // Generate CSR // signed by private key var kp = rs.KEYUTIL.generateKeypair("RSA", "2048"); var prv = kp.prvKeyObj; var pub = kp.pubKeyObj; var prvpem = rs.KEYUTIL.getPEM(prv, "PKCS8PRV"); var pubpem = rs.KEYUTIL.getPEM(pub, "PKCS8PUB");

let csr = new rs.KJUR.asn1.csr.CertificationRequest({
    subject: {str:"/C=US/O=Test"},
    sbjpubkey: pubpem,//  "-----BEGIN PUBLIC KEY...",
    extreq: [{extname:"subjectAltName",array:[{dns:"example.com"}]}],
    sigalg: "SHA256withRSA",
    sbjprvkey: prvpem // "-----BEGIN PRIVATE KEY..."
});

let pem = csr.getPEM(); // signed with sbjprvkey automatically
console.log(pem);

} catch (err) { console.log(err); }