jsrsasign

repository·master·Indexed 25 days ago

https://github.com/kjur/jsrsasign

A pure JavaScript cryptographic library supporting RSA, RSAPSS, ECDSA, and DSA signing/validation. It provides comprehensive support for ASN.1, PKCS#1/5/8 keys, X.509 certificates, CRL, OCSP, CMS SignedData, TimeStamp, CAdES, and JSON Web Signature (JWS), Token (JWT), and Key (JWK). Includes a utility package, jsrsasign-util, for file I/O operations.

Tokens
6.7K
Snippets
9
Records
73
Agent score
85%

What's inside jsrsasign

  1. Install and use jsrsasign-util

    master

    The jsrsasign-util package provides supplementary functions for the main jsrsasign library, specifically focusing on file I/O utilities like reading and saving files in various formats (binary, hex, UTF-8).

    var rsu = require('jsrsasign-util');
  2. Install required npm packages for Node.js scripts

    master

    To use the sample Node.js utility scripts provided in this repository, you must install the following npm packages globally. Since version 6.0.0, logic involving the fs module has been moved to jsrsasign-util, making it a required dependency alongside jsrsasign and commander.

    % npm install -g commander
    % npm install -g jsrsasign
    % npm install -g jsrsasign-util
  3. Include jsrsasign in HTML via CDN

    master

    To use the library in a browser environment without a package manager, include the minified script from a CDN.

    <script src="https://cdnjs.cloudflare.com/ajax/libs/jsrsasign/8.0.20/jsrsasign-all-min.js"></script>
  4. Important notice regarding jsrsasign support and security

    master

    End of Support

    As of 14 April 2026, support for jsrsasign has ended. Effective 3 June 2026, all npm packages for jsrsasign are deprecated.

    Security Advisory: Marvin Attack

    Due to the Marvin attack vulnerability (CVE-2024-21484), RSA PKCS#1.5 and RSAOAEP encryption/decryption are no longer supported in version 11.0.0 and later.

  5. Example of file I/O with jsrsasign-util

    master

    This example demonstrates how to require the utility module, read a binary file, and save a file from a hexadecimal string.

    var rsu = require('jsrsasign-util');
    var rawString = rsu.readFile("bar.bin");
    rsu.saveFileBinByHex("foo.bin", "30143abb...");
  6. Load an encrypted PKCS#5 private key

    master

    To load an encrypted PKCS#5 private key, use jsrsasign-util to read the file and jsrsasign.KEYUTIL.getKey to parse it with the provided password.

    var rs = require('jsrsasign');
    var rsu = require('jsrsasign-util');
    var pem = rsu.readFile('z1.prv.p5e.pem');
    var prvKey = rs.KEYUTIL.getKey(pem, 'passwd');
  7. Sign a string with a private key

    master

    To sign a string using a loaded private key, instantiate a Signature object with the desired algorithm (e.g., 'SHA1withRSA'), initialize it with the private key, update it with the string content, and call .sign().

    var sig = new Signature({alg: 'SHA1withRSA'});
    sig.init(prvKey);
    sig.updateString('aaa');
    var sigVal = sig.sign();
    // sigVal contains the signature