获取 ssh-rsa public 密钥的模数?
Get modulus of ssh-rsa public key?
我正在尝试使用 Auth0 的库 idtoken-verifier 在客户端验证 JWT,但在检查我的 public 密钥 (https://github.com/auth0/idtoken-verifier/blob/master/src/helpers/rsa-verifier.js#L25)[= 的模数和指数时出现错误19=]
Public键: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/ 等),但没有成功。
public 密钥采用 ssh-rsa 密钥格式。应该先转换成PEM:
ssh-keygen -f key.pub -e -m pem
使用您提供的密钥,结果将是:
-----BEGIN RSA PUBLIC KEY-----
MIIBCgKCAQEA5oPUwoHi/mkxa6+jImfxV3LofOOl5UCx4AzCBw1++Mdc8Dz5cfr6
Kse7DuGB+MM5lI6AOl1EY/bWUsBZ1gZEp7XLxDEC6Dd8nSqUr9JvCvAkJzopmaER
+cxHRp5BtqyLMHKG7mql1GB6i5kFdfr8WPknF+Ov9PnVZi3YWPUo3YJE7Dtzdxhp
Rl2SC/dp5gVcw9YESmzE/S8dGah8E1Bk8VHAODsTaIyEWF+gdMW8ggTpTp9qeJYT
lyRPFMqbx8+r4Zj/RZAqqwFVv4otEtoUJ4UfGmEAC7MkDooPiLUfdlcxovyslC8d
34jXXmHv65cUX36TU1q7p/cbjOmmcAS0aQIDAQAB
-----END RSA PUBLIC KEY-----
有关此密钥的解码版本,请参阅 lapo.it/asn1js。
我正在尝试使用 Auth0 的库 idtoken-verifier 在客户端验证 JWT,但在检查我的 public 密钥 (https://github.com/auth0/idtoken-verifier/blob/master/src/helpers/rsa-verifier.js#L25)[= 的模数和指数时出现错误19=]
Public键: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/ 等),但没有成功。
public 密钥采用 ssh-rsa 密钥格式。应该先转换成PEM:
ssh-keygen -f key.pub -e -m pem
使用您提供的密钥,结果将是:
-----BEGIN RSA PUBLIC KEY-----
MIIBCgKCAQEA5oPUwoHi/mkxa6+jImfxV3LofOOl5UCx4AzCBw1++Mdc8Dz5cfr6
Kse7DuGB+MM5lI6AOl1EY/bWUsBZ1gZEp7XLxDEC6Dd8nSqUr9JvCvAkJzopmaER
+cxHRp5BtqyLMHKG7mql1GB6i5kFdfr8WPknF+Ov9PnVZi3YWPUo3YJE7Dtzdxhp
Rl2SC/dp5gVcw9YESmzE/S8dGah8E1Bk8VHAODsTaIyEWF+gdMW8ggTpTp9qeJYT
lyRPFMqbx8+r4Zj/RZAqqwFVv4otEtoUJ4UfGmEAC7MkDooPiLUfdlcxovyslC8d
34jXXmHv65cUX36TU1q7p/cbjOmmcAS0aQIDAQAB
-----END RSA PUBLIC KEY-----
有关此密钥的解码版本,请参阅 lapo.it/asn1js。