获取ssh-rsa公钥的模数?

时间:2019-05-03 17:03:12

标签: ssh cryptography jwt rsa public-key

我正在尝试使用Auth0的库idtoken-verifier验证客户端的JWT,并在检查我的公钥(https://github.com/auth0/idtoken-verifier/blob/master/src/helpers/rsa-verifier.js#L25)的模数和指数时抛出错误

公钥:ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDmg9TCgeL+aTFrr6MiZ/FXcuh846XlQLHgDMIHDX74x1zwPPlx+voqx7sO4YH4wzmUjoA6XURj9tZSwFnWBkSntcvEMQLoN3ydKpSv0m8K8CQnOimZoRH5zEdGnkG2rIswcobuaqXUYHqLmQV1+vxY+ScX46/0+dVmLdhY9SjdgkTsO3N3GGlGXZIL92nmBVzD1gRKbMT9Lx0ZqHwTUGTxUcA4OxNojIRYX6B0xbyCBOlOn2p4lhOXJE8UypvHz6vhmP9FkCqrAVW/ii0S2hQnhR8aYQALsyQOig+ItR92VzGi/KyULx3fiNdeYe/rlxRffpNTWrun9xuM6aZwBLRp

我找不到有关如何从ssh-keygen生成的密钥中获取模数和exp的任何信息,因此我尝试在this post的帮助下手动将其提取以获取:

exp :AQAB-> 65537

模量AQDmg9TCgeL+aTFrr6MiZ/FXcuh846XlQLHgDMIHDX74x1zwPPlx+voqx7sO4YH4wzmUjoA6XURj9tZSwFnWBkSntcvEMQLoN3ydKpSv0m8K8CQnOimZoRH5zEdGnkG2rIswcobuaqXUYHqLmQV1+vxY+ScX46/0+dVmLdhY9SjdgkTsO3N3GGlGXZIL92nmBVzD1gRKbMT9Lx0ZqHwTUGTxUcA4OxNojIRYX6B0xbyCBOlOn2p4lhOXJE8UypvHz6vhmP9FkCqrAVW/ii0S2hQnhR8aYQALsyQOig+ItR92VzGi/KyULx3fiNdeYe/rlxRffpNTWrun9xuM6aZwBLRp

这是库中的函数

function RSAVerifier(modulus, exp) {
  this.n = null;
  this.e = 0;

  if (modulus != null && exp != null && modulus.length > 0 && exp.length > 0) {
    this.n = new BigInteger(modulus, 16);
    this.e = parseInt(exp, 16);
  } else {
    throw new Error('Invalid key data');
  }
}

验证者

const verifier = new IdTokenVerifier({
  issuer: 'https://somevalidurl.com',
  audience: 'access',
  expectedAlg: 'RS256',
  jwksCache: new DummyCache(),
});

DummyCache()

class DummyCache {
  get() {
    let keyInfo = {
      'modulus': ??????,
      'exp': 65537,
    }
    return keyInfo;
  }
  has() {
    return true;
  }
  set() {
    return null;
  }
}

我想我对模数参数的期望感到困惑,我试图将上述模数转换为几种不同的形式(十六进制,通过https://lapo.it/asn1js/等),以至于没有运气。