How to use the createCredentials function from crypto

Find comprehensive JavaScript crypto.createCredentials code examples handpicked from public code repositorys.

188
189
190
191
192
193
194
195
196
197

var self = this;
var options = this._tlsOptions;

// Wrap socket's handle
var credentials = options.credentials || crypto.createCredentials();
this.ssl = tls_wrap.wrap(this._handle, credentials.context, options.isServer);
this.server = options.server || null;

// For clients, we will always have either a given ca list or be using
fork icon1
star icon9
watch icon6

327
328
329
330
331
332
333
334
335
336
//  _socket <-> _protocol
// after:
//  _socket <-> securePair.encrypted <-> securePair.cleartext <-> _protocol

var connection  = this;
var credentials = Crypto.createCredentials({
  ca         : this.config.ssl.ca,
  cert       : this.config.ssl.cert,
  ciphers    : this.config.ssl.ciphers,
  key        : this.config.ssl.key,
fork icon0
star icon1
watch icon1

44
45
46
47
48
49
50
51
52
this._done = false;

var crypto = require('crypto');

if (!credentials) {
  this.credentials = crypto.createCredentials();
} else {
  this.credentials = credentials;
}
fork icon0
star icon1
watch icon2

115
116
117
118
119
120
121
122
123
124
 * @return {Object} secure context
 */
function secureContext(key, crt, ca) {
	var ctx;
	if (_NODE_VERSION === 10) {
		ctx = crypto.createCredentials({key: key, cert: crt, ca: ca});
	} else {
		// Versions 11 or 1.x or above
		ctx = tls.createSecureContext({key: key, cert: crt, ca: ca});
	}
fork icon0
star icon0
watch icon0

311
312
313
314
315
316
317
318
319
320

The `key` is the raw key used by the `algorithm` and `iv` is an
[initialization vector][]. Both arguments must be `'binary'` encoded strings or
[buffers][].

### crypto.createCredentials(details)

    Stability: 0 - Deprecated: Use [`tls.createSecureContext`][] instead.

The `crypto.createCredentials()` method is a deprecated alias for creating
fork icon0
star icon0
watch icon1