Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

May I ask a question #3

Open
349989153 opened this issue Jun 22, 2018 · 3 comments
Open

May I ask a question #3

349989153 opened this issue Jun 22, 2018 · 3 comments

Comments

@349989153
Copy link

349989153 commented Jun 22, 2018

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
Copy link
Author

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

@lchung0
Copy link

lchung0 commented Jul 25, 2018

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

@349989153
Copy link
Author

@lchung0 Ok, my mistake, sorry

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants