@@ -294,7 +294,10 @@ describe('NodeRSA', function () {
294294 'pkcs8-private' : { public : false , der : false , file : 'private_pkcs8.pem' } ,
295295 'pkcs8-der' : { public : false , der : true , file : 'private_pkcs8.der' } ,
296296 'pkcs1-public' : { public : true , der : false , file : 'public_pkcs1.pem' } ,
297- 'pkcs8-public' : { public : true , der : false , file : 'public_pkcs8.pem' }
297+ 'pkcs8-public' : { public : true , der : false , file : 'public_pkcs8.pem' } ,
298+
299+ 'openssh-public' : { public : true , der : false , file : 'id_rsa.pub' } ,
300+ 'openssh-private' : { public : false , der : false , file : 'id_rsa' }
298301 } ;
299302
300303 describe ( 'Good cases' , function ( ) {
@@ -483,6 +486,36 @@ describe('NodeRSA', function () {
483486 } ) ( format ) ;
484487 }
485488 } ) ;
489+
490+ describe ( 'OpenSSH keys' , function ( ) {
491+ /*
492+ * Warning!
493+ * OpenSSH private key contains unused 64bit value, this value is set by ssh-keygen,
494+ * but it's not used. NodeRSA does NOT store this value, so importing and exporting key sets this value to 0.
495+ * This value is 0 in test files, so the tests pass.
496+ */
497+ it ( 'key export should preserve key data including comment' , function ( ) {
498+ const opensshPrivateKey = fs . readFileSync ( keysFolder + 'id_rsa_comment' ) . toString ( ) ;
499+ const opensshPublicKey = fs . readFileSync ( keysFolder + 'id_rsa_comment.pub' ) . toString ( ) ;
500+ const opensshPriv = new NodeRSA ( opensshPrivateKey ) ;
501+ const opensshPub = new NodeRSA ( opensshPublicKey ) ;
502+
503+ assert . equal (
504+ opensshPriv . exportKey ( 'openssh-private' ) ,
505+ opensshPrivateKey
506+ ) ;
507+
508+ assert . equal (
509+ opensshPriv . exportKey ( 'openssh-public' ) ,
510+ opensshPublicKey
511+ ) ;
512+
513+ assert . equal (
514+ opensshPub . exportKey ( 'openssh-public' ) ,
515+ opensshPublicKey
516+ ) ;
517+ } ) ;
518+ } )
486519 } ) ;
487520
488521 describe ( 'Bad cases' , function ( ) {
0 commit comments