dojox/encoding/crypto/RSAKey-ext.js

  • Provides:

    • dojox.encoding.crypto.RSAKey-ext
  • dojox.encoding.crypto.RSAKey.setPrivate

    • type
      Function
    • parameters:
      • N: (typeof )
      • E: (typeof )
      • D: (typeof )
    • source: [view]
         if(N && E && N.length && E.length){
          this.n = new BigInteger(N, 16);
          this.e = parseInt(E, 16);
          this.d = new BigInteger(D, 16);
         }else{
          throw new Error("Invalid RSA private key");
         }
    • summary
      Set the private key fields N, e, d and CRT params from hex strings
  • dojox.encoding.crypto.RSAKey.n

    • summary
  • dojox.encoding.crypto.RSAKey.e

    • summary
  • dojox.encoding.crypto.RSAKey.d

    • summary
  • dojox.encoding.crypto.RSAKey.setPrivateEx

    • type
      Function
    • parameters:
      • N: (typeof )
      • E: (typeof )
      • D: (typeof )
      • P: (typeof )
      • Q: (typeof )
      • DP: (typeof )
      • DQ: (typeof )
      • C: (typeof )
    • source: [view]
         if(N && E && N.length && E.length){
          this.n = new BigInteger(N, 16);
          this.e = parseInt(E, 16);
          this.d = new BigInteger(D, 16);
          this.p = new BigInteger(P, 16);
          this.q = new BigInteger(Q, 16);
          this.dmp1 = new BigInteger(DP, 16);
          this.dmq1 = new BigInteger(DQ, 16);
          this.coeff = new BigInteger(C, 16);
         }else{
          throw new Error("Invalid RSA private key");
         }
    • summary
      Set the private key fields N, e, d and CRT params from hex strings
  • dojox.encoding.crypto.RSAKey.p

    • summary
  • dojox.encoding.crypto.RSAKey.q

    • summary
  • dojox.encoding.crypto.RSAKey.dmp1

    • summary
  • dojox.encoding.crypto.RSAKey.dmq1

    • summary
  • dojox.encoding.crypto.RSAKey.coeff

    • summary
  • dojox.encoding.crypto.RSAKey.generate

    • type
      Function
    • parameters:
      • B: (typeof )
      • E: (typeof )
    • source: [view]
         var rng = this.rngf(), qs = B >> 1;
         this.e = parseInt(E, 16);
         var ee = new BigInteger(E, 16);
         for(;;) {
          for(;;) {
           this.p = new BigInteger(B - qs, 1, rng);
           if(!this.p.subtract(BigInteger.ONE).gcd(ee).compareTo(BigInteger.ONE) && this.p.isProbablePrime(10)){
            break;
           }
          }
          for(;;) {
           this.q = new BigInteger(qs, 1, rng);
           if(!this.q.subtract(BigInteger.ONE).gcd(ee).compareTo(BigInteger.ONE) && this.q.isProbablePrime(10)){
            break;
           }
          }
          if(this.p.compareTo(this.q) <= 0) {
           var t = this.p;
           this.p = this.q;
           this.q = t;
          }
          var p1 = this.p.subtract(BigInteger.ONE);
          var q1 = this.q.subtract(BigInteger.ONE);
          var phi = p1.multiply(q1);
          if(!phi.gcd(ee).compareTo(BigInteger.ONE)) {
           this.n = this.p.multiply(this.q);
           this.d = ee.modInverse(phi);
           this.dmp1 = this.d.mod(p1);
           this.dmq1 = this.d.mod(q1);
           this.coeff = this.q.modInverse(this.p);
           break;
          }
         }
         rng.destroy();
    • summary
      Generate a new random private key B bits long, using public expt E
  • dojox.encoding.crypto.RSAKey.decrypt

    • type
      Function
    • parameters:
      • ctext: (typeof String)
        an even-length hex string
    • source: [view]
         var c = new BigInteger(ctext, 16), m;
         if(!this.p || !this.q){
          m = c.modPow(this.d, this.n);
         }else{
          // TODO: re-calculate any missing CRT params
          var cp = c.mod(this.p).modPow(this.dmp1, this.p),
           cq = c.mod(this.q).modPow(this.dmq1, this.q);
          while(cp.compareTo(cq) < 0){
           cp = cp.add(this.p);
          }
          m = cp.subtract(cq).multiply(this.coeff).mod(this.p).multiply(this.q).add(cq);
         }
         if(!m){
          return null;
         }
         return pkcs1unpad2(m, (this.n.bitLength() + 7) >> 3);
    • summary
      Return the PKCS#1 RSA decryption of &quot;ctext&quot;.
    • return_summary
      a plain string.
  • dojox.encoding.crypto.RSAKey-ext

    • type
      Object
    • summary
  • dojox.encoding.crypto

    • type
      Object
    • summary
  • dojox.encoding

    • type
      Object
    • summary
  • dojox

    • type
      Object
    • summary