How to use the jsrsasign.SecureRandom function in jsrsasign

To help you get started, we’ve selected a few jsrsasign examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ovanwijk / iota-pay / src / iota-pay-static.js View on Github external
export async function generateECDSAKeyPairFromSeed(originSeed) {
    
    //This method is here to replace the SecureRandom generator native to jsrasign with
    //a seeded version. They both use prng random numbers.

    //seed the prng random generator   
    var seededRandom = new SeedRandom(CryptoJS.SHA512(originSeed).toString());

    //save the original random generator.
    var oldNextBytes = jrsa.SecureRandom.prototype.nextBytes;

    //create a new nextBytes function based on a SeedRandom method
    var SeededRandomNextBytes = function(ba) {
        var i;        
        for (i = 0; i < ba.length; i++) {
            ba[i] = Math.floor(seededRandom() * 256); // make it bytes.
        }
    }

    //Replace the random function
    jrsa.SecureRandom.prototype.nextBytes = SeededRandomNextBytes;

    var ecKeypair = jrsa.KEYUTIL.generateKeypair("EC", "secp256k1");     
  
    //just put back the old random function after generation.
    jrsa.SecureRandom.prototype.nextBytes = oldNextBytes;
github ovanwijk / iota-pay / src / iota-pay-static.js View on Github external
//create a new nextBytes function based on a SeedRandom method
    var SeededRandomNextBytes = function(ba) {
        var i;        
        for (i = 0; i < ba.length; i++) {
            ba[i] = Math.floor(seededRandom() * 256); // make it bytes.
        }
    }

    //Replace the random function
    jrsa.SecureRandom.prototype.nextBytes = SeededRandomNextBytes;

    var ecKeypair = jrsa.KEYUTIL.generateKeypair("EC", "secp256k1");     
  
    //just put back the old random function after generation.
    jrsa.SecureRandom.prototype.nextBytes = oldNextBytes;
    // debugger;
    // var jwkPrivate = jrsa.KEYUTIL.getJWKFromKey(ecKeypair.prvKeyObj);
    // var jwkPublic = jrsa.KEYUTIL.getJWKFromKey(ecKeypair.prvKeyObj);
    // debugger;
    return {
        privateKey: jrsa.KEYUTIL.getPEM(ecKeypair.prvKeyObj, "PKCS8PRV"),
        publicKey: jrsa.KEYUTIL.getPEM(ecKeypair.pubKeyObj)
    };;

}

jsrsasign

opensource free pure JavaScript cryptographic library supports RSA/RSAPSS/ECDSA/DSA signing/validation, ASN.1, PKCS#1/5/8 private/public key, X.509 certificate, CRL, OCSP, CMS SignedData, TimeStamp and CAdES and JSON Web Signature(JWS)/Token(JWT)/Key(JWK)

MIT
Latest version published 3 months ago

Package Health Score

75 / 100
Full package analysis