Skip to content

Commit 9dfd043

Browse files
committed
Merge pull request #8 from goloroden/master
Fixes loading PEM files with trailing line-break. #7
2 parents 31109c7 + 18790ac commit 9dfd043

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/NodeRSA.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ module.exports = (function() {
6161
* @param pem {string}
6262
*/
6363
NodeRSA.prototype.loadFromPEM = function(pem) {
64-
if (/^-----BEGIN RSA PRIVATE KEY-----\s([A-Za-z0-9+/=]+\s)+-----END RSA PRIVATE KEY-----$/g.test(pem)) {
64+
if (/^-----BEGIN RSA PRIVATE KEY-----\s([A-Za-z0-9+/=]+\s)+-----END RSA PRIVATE KEY-----\s*$/g.test(pem)) {
6565
this.$loadFromPrivatePEM(pem, 'base64');
66-
} else if (/^-----BEGIN PUBLIC KEY-----\s([A-Za-z0-9+/=]+\s)+-----END PUBLIC KEY-----$/g.test(pem)) {
66+
} else if (/^-----BEGIN PUBLIC KEY-----\s([A-Za-z0-9+/=]+\s)+-----END PUBLIC KEY-----\s*$/g.test(pem)) {
6767
this.$loadFromPublicPEM(pem, 'base64');
6868
} else
6969
throw Error('Invalid PEM format');
@@ -365,4 +365,4 @@ module.exports = (function() {
365365
};
366366

367367
return NodeRSA;
368-
})();
368+
})();

0 commit comments

Comments
 (0)