@@ -38,6 +38,7 @@ const decryptError = {
38
38
{
39
39
const input = 'I AM THE WALRUS' ;
40
40
const bufferToEncrypt = Buffer . from ( input ) ;
41
+ const bufferPassword = Buffer . from ( 'password' ) ;
41
42
42
43
let encryptedBuffer = crypto . publicEncrypt ( rsaPubPem , bufferToEncrypt ) ;
43
44
@@ -66,33 +67,33 @@ const decryptError = {
66
67
67
68
encryptedBuffer = crypto . privateEncrypt ( {
68
69
key : rsaKeyPemEncrypted ,
69
- passphrase : Buffer . from ( 'password' )
70
+ passphrase : bufferPassword
70
71
} , bufferToEncrypt ) ;
71
72
72
73
decryptedBufferWithPassword = crypto . publicDecrypt ( {
73
74
key : rsaKeyPemEncrypted ,
74
- passphrase : Buffer . from ( 'password' )
75
+ passphrase : bufferPassword
75
76
} , encryptedBuffer ) ;
76
77
assert . strictEqual ( decryptedBufferWithPassword . toString ( ) , input ) ;
77
78
78
79
// Now with explicit RSA_PKCS1_PADDING.
79
80
encryptedBuffer = crypto . privateEncrypt ( {
80
81
padding : crypto . constants . RSA_PKCS1_PADDING ,
81
82
key : rsaKeyPemEncrypted ,
82
- passphrase : Buffer . from ( 'password' )
83
+ passphrase : bufferPassword
83
84
} , bufferToEncrypt ) ;
84
85
85
86
decryptedBufferWithPassword = crypto . publicDecrypt ( {
86
87
padding : crypto . constants . RSA_PKCS1_PADDING ,
87
88
key : rsaKeyPemEncrypted ,
88
- passphrase : Buffer . from ( 'password' )
89
+ passphrase : bufferPassword
89
90
} , encryptedBuffer ) ;
90
91
assert . strictEqual ( decryptedBufferWithPassword . toString ( ) , input ) ;
91
92
92
93
// Omitting padding should be okay because RSA_PKCS1_PADDING is the default.
93
94
decryptedBufferWithPassword = crypto . publicDecrypt ( {
94
95
key : rsaKeyPemEncrypted ,
95
- passphrase : Buffer . from ( 'password' )
96
+ passphrase : bufferPassword
96
97
} , encryptedBuffer ) ;
97
98
assert . strictEqual ( decryptedBufferWithPassword . toString ( ) , input ) ;
98
99
@@ -101,13 +102,13 @@ const decryptError = {
101
102
encryptedBuffer = crypto . privateEncrypt ( {
102
103
padding : crypto . constants . RSA_NO_PADDING ,
103
104
key : rsaKeyPemEncrypted ,
104
- passphrase : Buffer . from ( 'password' )
105
+ passphrase : bufferPassword
105
106
} , Buffer . from ( plaintext ) ) ;
106
107
107
108
decryptedBufferWithPassword = crypto . publicDecrypt ( {
108
109
padding : crypto . constants . RSA_NO_PADDING ,
109
110
key : rsaKeyPemEncrypted ,
110
- passphrase : Buffer . from ( 'password' )
111
+ passphrase : bufferPassword
111
112
} , encryptedBuffer ) ;
112
113
assert . strictEqual ( decryptedBufferWithPassword . toString ( ) , plaintext ) ;
113
114
0 commit comments