@@ -102,14 +102,18 @@ Example: Using `Cipher` objects as streams:
102102const crypto = require (' crypto' );
103103const cipher = crypto .createCipher (' aes192' , ' a password' );
104104
105+ var encrypted = ' ' ;
105106cipher .on (' readable' , () => {
106107 var data = cipher .read ();
107108 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
110114});
111115
112- cipher .write (' clear text data' );
116+ cipher .write (' some clear text data' );
113117cipher .end ();
114118```
115119
@@ -132,9 +136,10 @@ Example: Using the `cipher.update()` and `cipher.final()` methods:
132136const crypto = require (' crypto' );
133137const cipher = crypto .createCipher (' aes192' , ' a password' );
134138
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
138143```
139144
140145### cipher.final([ output_encoding] )
@@ -212,14 +217,19 @@ Example: Using `Decipher` objects as streams:
212217const crypto = require (' crypto' );
213218const decipher = crypto .createDecipher (' aes192' , ' a password' );
214219
220+ var decrypted = ' ' ;
215221decipher .on (' readable' , () => {
216222 var data = decipher .read ();
217223 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
220229});
221230
222- decipher .write (' b919f20fc5ac2f9c1d2cce94cb1d9c2d' , ' hex' );
231+ var encrypted = ' ca981be48e90867604588e75d04feabb63cc007a8f8ad89b10616ed84d815504' ;
232+ decipher .write (encrypted, ' hex' );
223233decipher .end ();
224234```
225235
@@ -242,9 +252,11 @@ Example: Using the `decipher.update()` and `decipher.final()` methods:
242252const crypto = require (' crypto' );
243253const decipher = crypto .createDecipher (' aes192' , ' a password' );
244254
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
248260```
249261
250262### decipher.final([ output_encoding] )
0 commit comments