@@ -102,14 +102,18 @@ Example: Using `Cipher` objects as streams:
102
102
const crypto = require (' crypto' );
103
103
const cipher = crypto .createCipher (' aes192' , ' a password' );
104
104
105
+ var encrypted = ' ' ;
105
106
cipher .on (' readable' , () => {
106
107
var data = cipher .read ();
107
108
if (data)
108
- console .log (data .toString (' hex' ));
109
- // Prints: b919f20fc5ac2f9c1d2cce94cb1d9c2d
109
+ encrypted += data .toString (' hex' );
110
+ });
111
+ cipher .on (' end' , () => {
112
+ console .log (encrypted);
113
+ // Prints: ca981be48e90867604588e75d04feabb63cc007a8f8ad89b10616ed84d815504
110
114
});
111
115
112
- cipher .write (' clear text data' );
116
+ cipher .write (' some clear text data' );
113
117
cipher .end ();
114
118
```
115
119
@@ -132,9 +136,10 @@ Example: Using the `cipher.update()` and `cipher.final()` methods:
132
136
const crypto = require (' crypto' );
133
137
const cipher = crypto .createCipher (' aes192' , ' a password' );
134
138
135
- cipher .update (' clear text data' );
136
- console .log (cipher .final (' hex' ));
137
- // Prints: b919f20fc5ac2f9c1d2cce94cb1d9c2d
139
+ var encrypted = cipher .update (' some clear text data' , ' utf8' , ' hex' );
140
+ encrypted += cipher .final (' hex' );
141
+ console .log (encrypted);
142
+ // Prints: ca981be48e90867604588e75d04feabb63cc007a8f8ad89b10616ed84d815504
138
143
```
139
144
140
145
### cipher.final([ output_encoding] )
@@ -212,14 +217,19 @@ Example: Using `Decipher` objects as streams:
212
217
const crypto = require (' crypto' );
213
218
const decipher = crypto .createDecipher (' aes192' , ' a password' );
214
219
220
+ var decrypted = ' ' ;
215
221
decipher .on (' readable' , () => {
216
222
var data = decipher .read ();
217
223
if (data)
218
- console .log (data .toString ());
219
- // Prints: clear text data
224
+ decrypted += data .toString (' utf8' );
225
+ });
226
+ decipher .on (' end' , () => {
227
+ console .log (decrypted);
228
+ // Prints: some clear text data
220
229
});
221
230
222
- decipher .write (' b919f20fc5ac2f9c1d2cce94cb1d9c2d' , ' hex' );
231
+ var encrypted = ' ca981be48e90867604588e75d04feabb63cc007a8f8ad89b10616ed84d815504' ;
232
+ decipher .write (encrypted, ' hex' );
223
233
decipher .end ();
224
234
```
225
235
@@ -242,9 +252,11 @@ Example: Using the `decipher.update()` and `decipher.final()` methods:
242
252
const crypto = require (' crypto' );
243
253
const decipher = crypto .createDecipher (' aes192' , ' a password' );
244
254
245
- decipher .update (' b919f20fc5ac2f9c1d2cce94cb1d9c2d' , ' hex' );
246
- console .log (decipher .final (' utf8' ));
247
- // Prints: clear text data
255
+ var encrypted = ' ca981be48e90867604588e75d04feabb63cc007a8f8ad89b10616ed84d815504' ;
256
+ var decrypted = decipher .update (encrypted, ' hex' , ' utf8' );
257
+ decrypted += decipher .final (' utf8' );
258
+ console .log (decrypted);
259
+ // Prints: some clear text data
248
260
```
249
261
250
262
### decipher.final([ output_encoding] )
0 commit comments