How to use jsbn - 10 common examples

To help you get started, we’ve selected a few jsbn 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 hardbyte / paillier.js / index.js View on Github external
}

    console.log("Generating new keypair with " + keysize + " bit length key");

    var p, q, n, g, phi_n, mu;
    var correctLength = false;
    while (!correctLength || p.compareTo(q) == 0){
        p = getprimeover(keysize>>1);
        q = getprimeover(keysize>>1);
        n = p.multiply(q);
        correctLength = n.testBit(keysize -1)
    }
    // simple paillier variant with g=n+1
    g = n.add(bn.ONE);

    phi_n = p.subtract(bn.ONE).multiply(q.subtract(bn.ONE));
    mu = phi_n.modInverse(n);

    var pubKey = exports.publicKey(g, n);

    /**
     * A KeyPair
     * @typedef KeyPair
     * @property {PublicKey} public_key
     * @property {PrivateKey} private_key
     * @property {number} n_length - The key length in bits
     * */
    return {
        public_key: pubKey,
        private_key: exports.privateKey(phi_n, mu, pubKey),
        n_length: keysize
    };
github wowserhq / wowser / src / lib / crypto / crypt.js View on Github external
set key(key) {
    console.info('initializing crypt');

    // Fresh RC4's
    this._encrypt = new RC4();
    this._decrypt = new RC4();

    // Calculate the encryption hash (through the server decryption key)
    const enckey = ArrayUtil.fromHex('C2B3723CC6AED9B5343C53EE2F4367CE');
    const enchash = HMAC.fromArrays(enckey, key);

    // Calculate the decryption hash (through the client decryption key)
    const deckey = ArrayUtil.fromHex('CC98AE04E897EACA12DDC09342915357');
    const dechash = HMAC.fromArrays(deckey, key);

    // Seed RC4's with the computed hashes
    this._encrypt.init(enchash);
    this._decrypt.init(dechash);

    // Ensure the buffer is synchronized
    for (let i = 0; i < 1024; ++i) {
github wowserhq / wowser / src / lib / crypto / crypt.js View on Github external
set key(key) {
    console.info('initializing crypt');

    // Fresh RC4's
    this._encrypt = new RC4();
    this._decrypt = new RC4();

    // Calculate the encryption hash (through the server decryption key)
    const enckey = ArrayUtil.fromHex('C2B3723CC6AED9B5343C53EE2F4367CE');
    const enchash = HMAC.fromArrays(enckey, key);

    // Calculate the decryption hash (through the client decryption key)
    const deckey = ArrayUtil.fromHex('CC98AE04E897EACA12DDC09342915357');
    const dechash = HMAC.fromArrays(deckey, key);

    // Seed RC4's with the computed hashes
    this._encrypt.init(enchash);
    this._decrypt.init(dechash);

    // Ensure the buffer is synchronized
    for (let i = 0; i < 1024; ++i) {
      this._encrypt.next();
github wowserhq / wowser / src / lib / crypto / crypt.js View on Github external
set key(key) {
    console.info('initializing crypt');

    // Fresh RC4's
    this._encrypt = new RC4();
    this._decrypt = new RC4();

    // Calculate the encryption hash (through the server decryption key)
    const enckey = ArrayUtil.fromHex('C2B3723CC6AED9B5343C53EE2F4367CE');
    const enchash = HMAC.fromArrays(enckey, key);

    // Calculate the decryption hash (through the client decryption key)
    const deckey = ArrayUtil.fromHex('CC98AE04E897EACA12DDC09342915357');
    const dechash = HMAC.fromArrays(deckey, key);

    // Seed RC4's with the computed hashes
    this._encrypt.init(enchash);
    this._decrypt.init(dechash);

    // Ensure the buffer is synchronized
    for (let i = 0; i < 1024; ++i) {
      this._encrypt.next();
      this._decrypt.next();
    }
  }
github wowserhq / wowser / src / lib / crypto / crypt.js View on Github external
set key(key) {
    console.info('initializing crypt');

    // Fresh RC4's
    this._encrypt = new RC4();
    this._decrypt = new RC4();

    // Calculate the encryption hash (through the server decryption key)
    const enckey = ArrayUtil.fromHex('C2B3723CC6AED9B5343C53EE2F4367CE');
    const enchash = HMAC.fromArrays(enckey, key);

    // Calculate the decryption hash (through the client decryption key)
    const deckey = ArrayUtil.fromHex('CC98AE04E897EACA12DDC09342915357');
    const dechash = HMAC.fromArrays(deckey, key);

    // Seed RC4's with the computed hashes
    this._encrypt.init(enchash);
    this._decrypt.init(dechash);

    // Ensure the buffer is synchronized
    for (let i = 0; i < 1024; ++i) {
      this._encrypt.next();
      this._decrypt.next();
    }
  }
github MyPureCloud / webrtc-troubleshooter / node_modules / babel-cli / node_modules / request / node_modules / http-signature / node_modules / sshpk / node_modules / ecc-jsbn / lib / ec.js View on Github external
V = result[1];

        if (this.modMult(V, V).equals(fourQ))
        {
            // Integer division by 2, mod q
            if (V.testBit(0))
            {
                V = V.add(q);
            }

            V = V.shiftRight(1);

            return new ECFieldElementFp(q,V);
        }
    }
    while (U.equals(BigInteger.ONE) || U.equals(qMinusOne));

    return null;
}
ECFieldElementFp.prototype.lucasSequence = function(P,Q,k)
github simbo1905 / thinbus-srp-npm / client.js View on Github external
SRP6JavascriptClientSession.prototype.computeU = function(Astr, Bstr) {
		"use strict";
		//console.log("SRP6JavascriptClientSession.prototype.computeU");
		this.check(Astr, "Astr");
		this.check(Bstr, "Bstr");
		/* jshint ignore:start */
		var output = this.H(Astr+Bstr);
		//console.log("js raw u:"+output);
		var u = new BigInteger(""+output,16);
		//console.log("js u:"+this.toHex(u));
		if( BigInteger.ZERO.equals(u) ) {
		throw new Error("SRP6Exception bad shared public value 'u' as u==0");
		}
		return u;
		/* jshint ignore:end */
	};
github simbo1905 / thinbus-srp-npm / server.js View on Github external
SRP6JavascriptServerSession.prototype.computeU = function(Astr, Bstr) {
    "use strict";
    //console.log("SRP6JavascriptServerSession.prototype.computeU");
    this.check(Astr, "Astr");
    this.check(Bstr, "Bstr");
    /* jshint ignore:start */
    var output = this.H(Astr+Bstr);
    //console.log("js raw u:"+output);
    var u = new BigInteger(""+output,16);
    //console.log("js u:"+this.toHex(u));
    if( BigInteger.ZERO.equals(u) ) {
      throw new Error("SRP6Exception bad shared public value 'u' as u==0");
    }
    return u;
    /* jshint ignore:end */
  };
github simbo1905 / thinbus-srp-npm / client.js View on Github external
this.check(s, "s");
		//console.log("s:" + s);
		this.check(BB, "BB");
		//console.log("BB:" + BB);
		
		if( this.state !== this.STEP_1 ) {
			throw new Error("IllegalStateException not in state STEP_1");
		}
		
		// this is checked when passed to computeSessionKey
		this.B = this.fromHex(BB); 

		var ZERO = null;
		
		/* jshint ignore:start */
		ZERO = BigInteger.ZERO;
		/* jshint ignore:end */
		
		if (this.B.mod(this.N()).equals(ZERO)) {
			throw new Error("SRP6Exception bad server public value 'B' as B == 0 (mod N)");
		}
		
		//console.log("k:" + this.k);

		// this is checked when passed to computeSessionKey
		var x = this.generateX(s, this.I, this.P);
		//console.log("x:" + x);

		// blank the password as there is no reason to keep it around in memory.
		this.P = null;

		//console.log("N:"+this.toHex(this.N).toString(16));
github simbo1905 / thinbus-srp-npm / client.js View on Github external
SRP6JavascriptClientSession.prototype.fromHex = function(s) {
		"use strict";
		return new BigInteger(""+s, 16); // jdk1.7 rhino requires string concat
	};
	/* jshint ignore:end */

jsbn

The jsbn library is a fast, portable implementation of large-number math in pure JavaScript, enabling public-key crypto and other applications on desktop and mobile browsers.

MIT
Latest version published 8 years ago

Package Health Score

67 / 100
Full package analysis