Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var crypto = require('crypto'); var CIPHER_ALGORITHM = 'aes-256-ctr'; function encrypt(key, input) { if (typeof key !== 'string' || !key) { throw new TypeError('Provided "key" must be a non-empty string'); } var isString = typeof input === 'string'; var isBuffer = Buffer.isBuffer(input); if (!(isString || isBuffer) || (isString && !input) || (isBuffer && !Buffer.byteLength(input))) { throw new TypeError('Provided "input" must be a non-empty string or buffer'); } var sha256 = crypto.createHash('sha256'); sha256.update(key); var iv = crypto.randomBytes(16); var cipher = crypto.createCipheriv(CIPHER_ALGORITHM, sha256.digest(), iv); var buffer = input; if (isString) { buffer = Buffer.from(input); } var ciphertext = cipher.update(buffer); var encrypted = Buffer.concat([iv, ciphertext, cipher.final()]); if (isString) { encrypted = encrypted.toString('base64'); } return encrypted; }
- const KEY = 'ПРИВАТНЫЙ_КЛЮЧ';
- const SALT = 'КЛЮЧ ДЛЯ ШИФРОВАНИЯ';
- console.log('Приватный ключ - ');
- console.log(encrypt(SALT,KEY))
Add Comment
Please, Sign In to add comment