Skip to content

Commit

Permalink
fix rsa public key can not detect in case:
Browse files Browse the repository at this point in the history
-----BEGIN RSA PUBLIC KEY-----
xxx...
-----END RSA PUBLIC KEY-----
  • Loading branch information
machine committed Dec 14, 2016
1 parent 0e0374f commit c7e5943
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/jsencrypt.js
Expand Up @@ -51,7 +51,6 @@ RSAKey.prototype.parseKey = function (pem) {
asn1 = asn1.sub[2].sub[0];
}
if (asn1.sub.length === 9) {

// Parse the private key.
modulus = asn1.sub[1].getHexStringValue(); //bigint
this.n = parseBigInt(modulus, 16);
Expand All @@ -76,19 +75,23 @@ RSAKey.prototype.parseKey = function (pem) {

var coefficient = asn1.sub[8].getHexStringValue(); //bigint
this.coeff = parseBigInt(coefficient, 16);

}
else if (asn1.sub.length === 2) {

// Parse the public key.
var bit_string = asn1.sub[1];
var sequence = bit_string.sub[0];
var sequence;
if (asn1.sub[0].tag == 0x02) {
// Parse the public key, without object identifier, then asn1.sub is a sequence of integers.
sequence = asn1;
}
else {
// Parse the public key, with object identifier, then asn1.sub[0] and asn1.sub[1] are sequences.
// asn1.sub[0] is a sequence included object identifier info, asn1.sub[1] is a sequence of integers.
sequence = asn1.sub[1].sub[0];
}

modulus = sequence.sub[0].getHexStringValue();
this.n = parseBigInt(modulus, 16);
public_exponent = sequence.sub[1].getHexStringValue();
this.e = parseInt(public_exponent, 16);

}
else {
return false;
Expand Down

0 comments on commit c7e5943

Please sign in to comment.