当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Node.js crypto.constants用法及代码示例


crypto.constants属性用于获取crypto和security-related操作的所有常用常量。这将返回包含加密常量的对象。

用法:

crypto.constants

返回值:此属性返回一个对象,其中包含加密模块中常用的常量。

例:本示例显示了加密模块中使用的所有常用常量。

index.js




// Importing the crypto library
const crypto = require("crypto")
  
// Storing the constants inside the variable
let constants = crypto.constants
  
// Printing the constants
console.log(constants)

使用以下命令运行index.js文件:

node index.js

输出:

[Object:null prototype] {
  OPENSSL_VERSION_NUMBER:269488303,
  SSL_OP_ALL:2147485780,
  SSL_OP_ALLOW_NO_DHE_KEX:1024,
  SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION:262144,
  SSL_OP_CIPHER_SERVER_PREFERENCE:4194304,
  SSL_OP_CISCO_ANYCONNECT:32768,
  SSL_OP_COOKIE_EXCHANGE:8192,
  SSL_OP_CRYPTOPRO_TLSEXT_BUG:2147483648,
  SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS:2048,
  SSL_OP_EPHEMERAL_RSA:0,
  SSL_OP_LEGACY_SERVER_CONNECT:4,
  SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER:0,
  SSL_OP_MICROSOFT_SESS_ID_BUG:0,
  SSL_OP_MSIE_SSLV2_RSA_PADDING:0,
  SSL_OP_NETSCAPE_CA_DN_BUG:0,
  SSL_OP_NETSCAPE_CHALLENGE_BUG:0,
  SSL_OP_NETSCAPE_DEMO_CIPHER_CHANGE_BUG:0,
  SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG:0,
  SSL_OP_NO_COMPRESSION:131072,
  SSL_OP_NO_ENCRYPT_THEN_MAC:524288,
  SSL_OP_NO_QUERY_MTU:4096,
  SSL_OP_NO_RENEGOTIATION:1073741824,
  SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION:65536,
  SSL_OP_NO_SSLv2:0,
  SSL_OP_NO_SSLv3:33554432,
  SSL_OP_NO_TICKET:16384,
  SSL_OP_NO_TLSv1:67108864,
  SSL_OP_NO_TLSv1_1:268435456,
  SSL_OP_NO_TLSv1_2:134217728,
  SSL_OP_NO_TLSv1_3:536870912,
  SSL_OP_PKCS1_CHECK_1:0,
  SSL_OP_PKCS1_CHECK_2:0,
  SSL_OP_PRIORITIZE_CHACHA:2097152,
  SSL_OP_SINGLE_DH_USE:0,
  SSL_OP_SINGLE_ECDH_USE:0,
  SSL_OP_SSLEAY_080_CLIENT_DH_BUG:0,
  SSL_OP_SSLREF2_REUSE_CERT_TYPE_BUG:0,
  SSL_OP_TLS_BLOCK_PADDING_BUG:0,
  SSL_OP_TLS_D5_BUG:0,
  SSL_OP_TLS_ROLLBACK_BUG:8388608,
  ENGINE_METHOD_RSA:1,
  ENGINE_METHOD_DSA:2,
  ENGINE_METHOD_DH:4,
  ENGINE_METHOD_RAND:8,
  ENGINE_METHOD_EC:2048,
  ENGINE_METHOD_CIPHERS:64,
  ENGINE_METHOD_DIGESTS:128,
  ENGINE_METHOD_PKEY_METHS:512,
  ENGINE_METHOD_PKEY_ASN1_METHS:1024,
  ENGINE_METHOD_ALL:65535,
  ENGINE_METHOD_NONE:0,
  DH_CHECK_P_NOT_SAFE_PRIME:2,
  DH_CHECK_P_NOT_PRIME:1,
  DH_UNABLE_TO_CHECK_GENERATOR:4,
  DH_NOT_SUITABLE_GENERATOR:8,
  ALPN_ENABLED:1,
  RSA_PKCS1_PADDING:1,
  RSA_SSLV23_PADDING:2,
  RSA_NO_PADDING:3,
  RSA_PKCS1_OAEP_PADDING:4,
  RSA_X931_PADDING:5,
  RSA_PKCS1_PSS_PADDING:6,
  RSA_PSS_SALTLEN_DIGEST:-1,
  RSA_PSS_SALTLEN_MAX_SIGN:-2,
  RSA_PSS_SALTLEN_AUTO:-2,
  defaultCoreCipherList:'TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_128_GCM_SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA384:DHE-RSA-AES256-SHA384:ECDHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA256:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!MD5:!PSK:!SRP:!CAMELLIA',
  TLS1_VERSION:769,
  TLS1_1_VERSION:770,
  TLS1_2_VERSION:771,
  TLS1_3_VERSION:772,
  POINT_CONVERSION_COMPRESSED:2,
  POINT_CONVERSION_UNCOMPRESSED:4,
  POINT_CONVERSION_HYBRID:6
}

参考:https://nodejs.org/api/crypto.html#crypto_crypto_constants

相关用法


注:本文由纯净天空筛选整理自_saurabh_jaiswal大神的英文原创作品 Node.js crypto.constants Property。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。