Учебник по Node.js

ГЛАВНАЯ СТРАНИЦА Node.js Введение в Node.js Node.js Начало работы Модули Node.js HTTP-модуль Node.js Файловая система Node.js URL-модуль Node.js Node.js NPM События Node.js Загрузить файлы Node.js Электронная почта Node.js

Node.js MySQL

Начать работу с MySQL MySQL Создать базу данных MySQL Создать таблицу MySQL вставить в MySQL выбрать из MySQL Где Порядок MySQL MySQL Удалить Таблица удаления MySQL Обновление MySQL Лимит MySQL MySQL присоединиться

Node.js MongoDB

Начать работу с MongoDB MongoDB Создать базу данных MongoDB Создать коллекцию Вставка MongoDB MongoDB Найти Запрос MongoDB Сортировка MongoDB MongoDB Удалить Коллекция MongoDB Drop Обновление MongoDB Лимит MongoDB Присоединиться к MongoDB

Малиновый Пи

Начать работу с RasPi Введение в RasPi GPIO Мигающий светодиод RasPi Светодиод RasPi и кнопка Проточные светодиоды RasPi Веб-сокет RasPi Веб-сокет со светодиодной подсветкой RasPi RGB Компоненты RasPi

Справочник по Node.js

Встроенные модули

Криптомодуль Node.js _

❮ Встроенные модули


Пример

Зашифровать текст 'abc'

var crypto = require('crypto');

var mykey = crypto.createCipher('aes-128-cbc', 'mypassword');
var mystr = mykey.update('abc', 'utf8', 'hex')
mystr += mykey.final('hex');

console.log(mystr); //34feb914c099df25794bf9ccb85bea72

Пример

Расшифровать обратно в 'abc'

var crypto = require('crypto');

var mykey = crypto.createDecipher('aes-128-cbc', 'mypassword');
var mystr = mykey.update('34feb914c099df25794bf9ccb85bea72', 'hex', 'utf8')
mystr += mykey.final('utf8');

console.log(mystr); //abc

Определение и использование

Модуль crypto обеспечивает способ обработки зашифрованных данных.


Синтаксис

Синтаксис включения криптомодуля в ваше приложение:

var crypto = require('crypto');

Крипто-свойства и методы

Method Description
constants Returns an object containing Crypto Constants
fips Checks if a FIPS crypto provider is in use
createCipher() Creates a Cipher object using the specific algorithm and password
createCipheriv() Creates a Cipher object using the specific algorithm, password and initialization vector
createDecipher() Creates a Decipher object using the specific algorithm and password
createDecipheriv() Creates a Decipher object using the specific algorithm, password and initialization vector
createDiffieHellman() Creates a DiffieHellman key exchange object
createECDH() Creates an Elliptic Curve Diffie Hellmann key exchange object
createHash() Creates a Hash object using the specified algorithm
createHmac() Creates a Hmac object using the specified algorithm and key
createSign() Creates a Sign object using the specified algorithm and key
createVerify() Creates a Verify object using the specified algorithm
getCiphers Returns an array of supported cipher algorithms
getCurves() Returns an array of supported elliptic curves
getDiffieHellman() Returns a predefined Diffie Hellman key exchange object
getHashes() Returns an array of supported hash algorithms
pbkdf2() Creates a Password Based Key Derivation Function 2 implementation
pbkdf2Sync() Creates a synchronous Password Based Key Derivation Function 2 implementation
privateDecrypt() Decrypts data using a private key
timingSafeEqual() Compare two Buffers and returns true is they are equal, otherwise false
privateEncrypt() Encrypts data using a private key
publicDecrypt() Decrypts data using a public key
publicEncrypt() Encrypts data using a public key
randomBytes() Creates random data
setEngine() Sets the engine for some or all OpenSSL function

❮ Встроенные модули