Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: Examples work when data exceeds buffer size #4811

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 24 additions & 12 deletions doc/api/crypto.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,18 @@ Example: Using `Cipher` objects as streams:
const crypto = require('crypto');
const cipher = crypto.createCipher('aes192', 'a password');

var encrypted = '';
cipher.on('readable', () => {
var data = cipher.read();
if (data)
console.log(data.toString('hex'));
// Prints: b919f20fc5ac2f9c1d2cce94cb1d9c2d
encrypted += data.toString('hex');
});
cipher.on('end', () => {
console.log(encrypted);
// Prints: ca981be48e90867604588e75d04feabb63cc007a8f8ad89b10616ed84d815504
});

cipher.write('clear text data');
cipher.write('some clear text data');
cipher.end();
```

Expand All @@ -132,9 +136,10 @@ Example: Using the `cipher.update()` and `cipher.final()` methods:
const crypto = require('crypto');
const cipher = crypto.createCipher('aes192', 'a password');

cipher.update('clear text data');
console.log(cipher.final('hex'));
// Prints: b919f20fc5ac2f9c1d2cce94cb1d9c2d
var encrypted = cipher.update('some clear text data', 'utf8', 'hex');
encrypted += cipher.final('hex');
console.log(encrypted);
// Prints: ca981be48e90867604588e75d04feabb63cc007a8f8ad89b10616ed84d815504
```

### cipher.final([output_encoding])
Expand Down Expand Up @@ -212,14 +217,19 @@ Example: Using `Decipher` objects as streams:
const crypto = require('crypto');
const decipher = crypto.createDecipher('aes192', 'a password');

var decrypted = '';
decipher.on('readable', () => {
var data = decipher.read();
if (data)
console.log(data.toString());
// Prints: clear text data
decrypted += data.toString('utf8');
});
decipher.on('end', () => {
console.log(decrypted);
// Prints: some clear text data
});

decipher.write('b919f20fc5ac2f9c1d2cce94cb1d9c2d', 'hex');
var encrypted = 'ca981be48e90867604588e75d04feabb63cc007a8f8ad89b10616ed84d815504';
decipher.write(encrypted, 'hex');
decipher.end();
```

Expand All @@ -242,9 +252,11 @@ Example: Using the `decipher.update()` and `decipher.final()` methods:
const crypto = require('crypto');
const decipher = crypto.createDecipher('aes192', 'a password');

decipher.update('b919f20fc5ac2f9c1d2cce94cb1d9c2d', 'hex');
console.log(decipher.final('utf8'));
// Prints: clear text data
var encrypted = 'ca981be48e90867604588e75d04feabb63cc007a8f8ad89b10616ed84d815504';
var decrypted = decipher.update(encrypted, 'hex', 'utf8');
decrypted += decipher.final('utf8');
console.log(decrypted);
// Prints: some clear text data
```

### decipher.final([output_encoding])
Expand Down