How to use the jsrsasign.crypto 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 bitpay / bitcore / test / index.js View on Github external
var sig = pr.get('signature');

      pki_data = PaymentProtocol.X509Certificates.decode(pki_data);
      pki_data = pki_data.certificate;

      ver.should.equal(1);
      pki_type.should.equal('x509+sha256');

      pki_data.length.should.equal(2);


      if (is_browser) {
        var type = 'SHA256';
        var pem = PaymentProtocol.prototype._DERtoPEM(pki_data[0], 'CERTIFICATE');
        var buf = pr.serializeForSig();
        var jsrsaSig = new KJUR.crypto.Signature({
          alg: type + 'withRSA',
          prov: 'cryptojs/jsrsa'
        });
        var signedCert = pki_data[0];
        var der = signedCert.toString('hex');
        // var pem = PaymentProtocol.DERtoPEM(der, 'CERTIFICATE');
        var pem = KJUR.asn1.ASN1Util.getPEMStringFromHex(der, 'CERTIFICATE');
        jsrsaSig.init(pem);
        jsrsaSig.updateHex(buf.toString('hex'));
        jsrsaSig.verify(sig.toString('hex')).should.equal(true);
      } else {
        var crypto = require('crypto');
        var type = 'SHA256';
        var pem = PaymentProtocol.DERtoPEM(pki_data[0], 'CERTIFICATE');
        var buf = pr.serializeForSig();
        var verifier = crypto.createVerify('RSA-' + type);
github bitpay / bitcore / packages / bitcore-payment-protocol / lib / browser.js View on Github external
PaymentProtocol.prototype.x509Sign = function(key, returnTrust) {
  var pki_type = this.get('pki_type');
  var pki_data = this.get('pki_data'); // contains one or more x509 certs
  pki_data = PaymentProtocol.X509Certificates.decode(pki_data);
  pki_data = pki_data.certificate;
  var type = pki_type !== 'none' ? pki_type.split('+')[1].toUpperCase() : pki_type;
  var buf = this.serializeForSig();

  var rsa = new KJUR.RSAKey();
  rsa.readPrivateKeyFromPEMString(key.toString());
  key = rsa;

  var sig;

  if (type !== 'none') {
    var jsrsaSig = new KJUR.crypto.Signature({
      alg: type + 'withRSA',
      prov: 'cryptojs/jsrsa'
    });

    jsrsaSig.init(key);

    jsrsaSig.updateHex(buf.toString('hex'));

    sig = new Buffer(jsrsaSig.sign(), 'hex');
  } else {
    sig = '';
  }

  if (returnTrust) {
    var cert = pki_data[pki_data.length - 1];
    var der = cert.toString('hex');
github satellity / satellity / app / src / api / user.js View on Github external
verify(params) {
    if (params.purpose === 'PASSWORD') {
      let data = {purpose: params.purpose, verification_id: params.verification_id, code: params.code, password: params.password};
      return this.api.axios.post(`/email_verifications/${params.verification_id}`, data)
    }
    let pwd = uuidv4().toLowerCase();
    let ec = new KJUR.crypto.ECDSA({'curve': 'secp256r1'});
    let pub = ec.generateKeyPairHex().ecpubhex;
    let priv = KJUR.KEYUTIL.getPEM(ec, 'PKCS8PRV', pwd);
    let data = {purpose: params.purpose, verification_id: params.verification_id, code: params.code, username: params.username, password: params.password, session_secret: this.fixed_schema_header + pub};
    return this.api.axios.post(`/email_verifications/${params.verification_id}`, data).then((resp) => {
      if (resp.error) {
        return resp;
      }
      let data = resp.data;
      Cookies.set('sid', pwd, { expires: 365 });
      window.localStorage.setItem('token', priv);
      window.localStorage.setItem('uid', data.user_id);
      window.localStorage.setItem('sid', data.session_id);
      window.localStorage.setItem('user', this.base64.encode(JSON.stringify(data)));
      return resp;
    });
  }
github satellity / satellity / web / src / api / user.js View on Github external
verify(params) {
    if (params.purpose === 'PASSWORD') {
      let data = {purpose: params.purpose, verification_id: params.verification_id, code: params.code, password: params.password};
      return this.api.axios.post(`/email_verifications/${params.verification_id}`, data)
    }
    let pwd = uuid().toLowerCase();
    let ec = new KJUR.crypto.ECDSA({'curve': 'secp256r1'});
    let pub = ec.generateKeyPairHex().ecpubhex;
    let priv = KJUR.KEYUTIL.getPEM(ec, 'PKCS8PRV', pwd);
    let data = {purpose: params.purpose, verification_id: params.verification_id, code: params.code, username: params.username, password: params.password, session_secret: this.fixed_schema_header + pub};
    return this.api.axios.post(`/email_verifications/${params.verification_id}`, data).then((resp) => {
      if (resp.error) {
        return resp;
      }
      let data = resp.data;
      Cookies.set('sid', pwd, { expires: 365 });
      window.localStorage.setItem('token', priv);
      window.localStorage.setItem('uid', data.user_id);
      window.localStorage.setItem('sid', data.session_id);
      window.localStorage.setItem('user', this.base64.encode(JSON.stringify(data)));
      return resp;
    });
  }
github IdentityModel / oidc-client-js / sample / oidc.js View on Github external
function hashAccessToken(access_token) {
    var hash = jsrsasign.crypto.Util.hashString(access_token, "sha256")
    var left = hash.substr(0, hash.length / 2);
    var left_b64u = jsrsasign.hextob64u(left);
    return left_b64u;
}

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 11 months ago

Package Health Score

74 / 100
Full package analysis