sm.js icon indicating copy to clipboard operation
sm.js copied to clipboard

May I ask a question

Open 349989153 opened this issue 6 years ago • 3 comments

There are two methods of SM2KeyPair: pubToString and toString.

I was wondering why there is no padding of this.pubwhen you call toString while there is 32 padding of this.pub when you call pubToString?

SM2KeyPair.prototype.toString = function() {
  var s = "public: ";
  if (this.pub) {
    s += "(" + this.pub.getX().toString(16) + ", " + this.pub.getY().toString(16) + ")";// no padding
  } else {
    s += "null";
  }
  s += ", private: ";
  if (this.pri) {
    s += this.pri.toString(16);
  } else {
    s += "null";
  }
  return s;
}
SM2KeyPair.prototype.pubToString = function(mode) {
  var s = '';
  switch (mode) {
    case 'compress':
      if (this.pub.getY().isEven()) {
        s = '02';
      } else {
        s = '03';
      }
      return s + this.pub.getX().toString(16, 32);
    case 'mix':
      if (this.pub.getY().isEven()) {
        s = '06';
      } else {
        s = '07';
      }
      break;
    default:
      s = '04'
  }
  return s + this.pub.getX().toString(16, 32) + this.pub.getY().toString(16, 32);// padding of 32
}

349989153 avatar Jun 22 '18 02:06 349989153

And what the hell var crypto = require('crypto');.Which package does 'crypto' stand for?It didn't save in the package.json

349989153 avatar Jul 20 '18 03:07 349989153

Maybe you should try it with nodejs ? It has the package 'crypto'

lchung0 avatar Jul 25 '18 12:07 lchung0

@lchung0 Ok, my mistake, sorry

349989153 avatar Jul 30 '18 02:07 349989153