@@ -366,6 +366,40 @@ describe('NodeRSA', function () {
366366 assert ( ! publicNodeRSA . isPrivate ( ) ) ;
367367 } ) ;
368368
369+ it ( 'should handle data without begin/end encapsulation boundaries for pkcs1 private keys' , function ( ) {
370+ let privateFile = fs . readFileSync ( keysFolder + 'private_pkcs1.pem' , "utf8" ) ;
371+ let privateFileNoBoundaries = privateFile . substring ( "-----BEGIN RSA PRIVATE KEY-----" . length , privateFile . indexOf ( "-----END RSA PRIVATE KEY-----" ) ) ;
372+ let key = new NodeRSA ( privateFileNoBoundaries , "pkcs1-private-pem" ) ;
373+ assert . equal ( key . exportKey ( ) , fileKeyPKCS1 ) ;
374+ } ) ;
375+
376+ it ( 'should handle data without begin/end encapsulation boundaries for pkcs1 public keys' , function ( ) {
377+ let publicFile = fs . readFileSync ( keysFolder + 'public_pkcs1.pem' , "utf8" ) ;
378+ let publicFileNoBoundaries = publicFile . substring ( "-----BEGIN RSA PUBLIC KEY-----" . length , publicFile . indexOf ( "-----END RSA PUBLIC KEY-----" ) ) ;
379+ let publicNodeRSA = new NodeRSA ( publicFileNoBoundaries , "pkcs1-public-pem" ) ;
380+ assert . instanceOf ( publicNodeRSA . keyPair , Object ) ;
381+ assert ( publicNodeRSA . isPublic ( ) ) ;
382+ assert ( publicNodeRSA . isPublic ( true ) ) ;
383+ assert ( ! publicNodeRSA . isPrivate ( ) ) ;
384+ } ) ;
385+
386+ it ( 'should handle data without begin/end encapsulation boundaries for pkcs8 private keys' , function ( ) {
387+ let privateFile = fs . readFileSync ( keysFolder + 'private_pkcs8.pem' , "utf8" ) ;
388+ let privateFileNoBoundaries = privateFile . substring ( '-----BEGIN PRIVATE KEY-----' . length , privateFile . indexOf ( '-----END PRIVATE KEY-----' ) ) ;
389+ let key = new NodeRSA ( privateFileNoBoundaries , "pkcs8-private-pem" ) ;
390+ assert . equal ( key . exportKey ( ) , fileKeyPKCS1 ) ;
391+ } ) ;
392+
393+ it ( 'should handle data without begin/end encapsulation boundaries for pkcs8 public keys' , function ( ) {
394+ let publicFile = fs . readFileSync ( keysFolder + 'public_pkcs8.pem' , "utf8" ) ;
395+ let publicFileNoBoundaries = publicFile . substring ( "-----BEGIN PUBLIC KEY-----" . length , publicFile . indexOf ( "-----END PUBLIC KEY-----" ) ) ;
396+ let publicNodeRSA = new NodeRSA ( publicFileNoBoundaries , "pkcs8-public-pem" ) ;
397+ assert . instanceOf ( publicNodeRSA . keyPair , Object ) ;
398+ assert ( publicNodeRSA . isPublic ( ) ) ;
399+ assert ( publicNodeRSA . isPublic ( true ) ) ;
400+ assert ( ! publicNodeRSA . isPrivate ( ) ) ;
401+ } ) ;
402+
369403 it ( '.importKey() from private components' , function ( ) {
370404 var key = new NodeRSA ( ) ;
371405 key . importKey ( {
0 commit comments