How to use the KeyObject function from crypto

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

190
191
192
193
194
195
196
197
198
createSecretKey = (buffer) => {
  if (!Buffer.isBuffer(buffer) || !buffer.length) {
    throw new TypeError('input must be a non-empty Buffer instance')
  }

  const keyObject = new KeyObject()
  i(keyObject).buffer = Buffer.from(buffer)
  i(keyObject).symmetricKeySize = buffer.length
  i(keyObject).type = 'secret'
fork icon279
star icon0
watch icon1

+ 3 other calls in file

58
59
60
61
62
63
64
65
66
67
  const privateKey = webKeyToPem(keys.privateKey, true)
  return { certificate: cert.toString('pem'), publicKey, privateKey }
}

function webKeyToPem (cryptoKey, isPrivate) {
  return crypto.KeyObject
    .from(cryptoKey)
    .export({ type: isPrivate ? 'pkcs8' : 'spki', format: 'pem' })
    .toString()
}
fork icon3
star icon90
watch icon8