fit: key size is now calculated instead of hardcoded

This commit is contained in:
Vladislav Hristov 2019-11-01 16:50:39 +02:00
parent ce6cd02e58
commit e8a80932e1

View File

@ -106,9 +106,7 @@ module.exports = class Key {
const key = this.keyIsPublic ? this.publicKey : this.privateKey; const key = this.keyIsPublic ? this.publicKey : this.privateKey;
const eKey = Buffer.from(key.e.toByteArray()); const eKey = Buffer.from(key.e.toByteArray());
return to === 'hex' return to === 'hex' ? eKey.toString('hex') : eKey;
? eKey.toString('hex')
: eKey;
} }
d() { d() {
@ -128,7 +126,10 @@ module.exports = class Key {
// eslint-disable-next-line class-methods-use-this // eslint-disable-next-line class-methods-use-this
size() { size() {
return 2048; const keyN = this.n('hex');
const bn = new BigInteger(keyN, 16);
return bn.bitLength();
} }
toPem() { toPem() {