From 6689679842e4044d141fbc8f20d2af702912a9f5 Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Tue, 19 Feb 2019 11:05:55 +0100 Subject: [PATCH 1/2] crypto: expose isKeyObject helper --- doc/api/crypto.md | 20 ++++++++++++++++++++ lib/crypto.js | 2 ++ lib/internal/crypto/keys.js | 4 ++-- test/parallel/test-crypto.js | 9 +++++++++ 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/doc/api/crypto.md b/doc/api/crypto.md index 72d4bc78df9dde..e6f4370e86ddaf 100644 --- a/doc/api/crypto.md +++ b/doc/api/crypto.md @@ -1121,6 +1121,9 @@ exposes different functions. Most applications should consider using the new `KeyObject` API instead of passing keys as strings or `Buffer`s due to improved security features. +See [`crypto.isKeyObject()`][] for checking whether a given input is +a `KeyObject` instance. + ### keyObject.asymmetricKeyType + +* `value` {any} +* Returns: {boolean} + +Returns `true` if the value is a [`KeyObject`] instance. + +```js +const crypto = require('crypto'); +const keypair = crypto.generateKeyPairSync('ec', { namedCurve: 'P-256' }); + +crypto.isKeyObject(keypair.privateKey); // Returns true +``` + ### crypto.pbkdf2(password, salt, iterations, keylen, digest, callback)