@@ -38,6 +38,7 @@ const decryptError = {
3838{
3939 const input = 'I AM THE WALRUS' ;
4040 const bufferToEncrypt = Buffer . from ( input ) ;
41+ const bufferPassword = Buffer . from ( 'password' ) ;
4142
4243 let encryptedBuffer = crypto . publicEncrypt ( rsaPubPem , bufferToEncrypt ) ;
4344
@@ -66,33 +67,33 @@ const decryptError = {
6667
6768 encryptedBuffer = crypto . privateEncrypt ( {
6869 key : rsaKeyPemEncrypted ,
69- passphrase : Buffer . from ( 'password' )
70+ passphrase : bufferPassword
7071 } , bufferToEncrypt ) ;
7172
7273 decryptedBufferWithPassword = crypto . publicDecrypt ( {
7374 key : rsaKeyPemEncrypted ,
74- passphrase : Buffer . from ( 'password' )
75+ passphrase : bufferPassword
7576 } , encryptedBuffer ) ;
7677 assert . strictEqual ( decryptedBufferWithPassword . toString ( ) , input ) ;
7778
7879 // Now with explicit RSA_PKCS1_PADDING.
7980 encryptedBuffer = crypto . privateEncrypt ( {
8081 padding : crypto . constants . RSA_PKCS1_PADDING ,
8182 key : rsaKeyPemEncrypted ,
82- passphrase : Buffer . from ( 'password' )
83+ passphrase : bufferPassword
8384 } , bufferToEncrypt ) ;
8485
8586 decryptedBufferWithPassword = crypto . publicDecrypt ( {
8687 padding : crypto . constants . RSA_PKCS1_PADDING ,
8788 key : rsaKeyPemEncrypted ,
88- passphrase : Buffer . from ( 'password' )
89+ passphrase : bufferPassword
8990 } , encryptedBuffer ) ;
9091 assert . strictEqual ( decryptedBufferWithPassword . toString ( ) , input ) ;
9192
9293 // Omitting padding should be okay because RSA_PKCS1_PADDING is the default.
9394 decryptedBufferWithPassword = crypto . publicDecrypt ( {
9495 key : rsaKeyPemEncrypted ,
95- passphrase : Buffer . from ( 'password' )
96+ passphrase : bufferPassword
9697 } , encryptedBuffer ) ;
9798 assert . strictEqual ( decryptedBufferWithPassword . toString ( ) , input ) ;
9899
@@ -101,13 +102,13 @@ const decryptError = {
101102 encryptedBuffer = crypto . privateEncrypt ( {
102103 padding : crypto . constants . RSA_NO_PADDING ,
103104 key : rsaKeyPemEncrypted ,
104- passphrase : Buffer . from ( 'password' )
105+ passphrase : bufferPassword
105106 } , Buffer . from ( plaintext ) ) ;
106107
107108 decryptedBufferWithPassword = crypto . publicDecrypt ( {
108109 padding : crypto . constants . RSA_NO_PADDING ,
109110 key : rsaKeyPemEncrypted ,
110- passphrase : Buffer . from ( 'password' )
111+ passphrase : bufferPassword
111112 } , encryptedBuffer ) ;
112113 assert . strictEqual ( decryptedBufferWithPassword . toString ( ) , plaintext ) ;
113114
0 commit comments