alexx876

Untitled

Jan 28th, 2022
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. var crypto = require('crypto'); var CIPHER_ALGORITHM = 'aes-256-ctr'; function decrypt(key, encrypted) { if (typeof key !== 'string' || !key) { throw new TypeError('Provided "key" must be a non-empty string'); } var isString = typeof encrypted === 'string'; var isBuffer = Buffer.isBuffer(encrypted); if (!(isString || isBuffer) || (isString && !encrypted) || (isBuffer && !Buffer.byteLength(encrypted))) { throw new TypeError('Provided "encrypted" must be a non-empty string or buffer'); } var sha256 = crypto.createHash('sha256'); sha256.update(key); var input = encrypted; if (isString) { input = Buffer.from(encrypted, 'base64'); if (input.length < 17) { throw new TypeError('Provided "encrypted" must decrypt to a non-empty string or buffer'); } } else { if (Buffer.byteLength(encrypted) < 17) { throw new TypeError('Provided "encrypted" must decrypt to a non-empty string or buffer'); } } var iv = input.slice(0, 16); var decipher = crypto.createDecipheriv(CIPHER_ALGORITHM, sha256.digest(), iv); var ciphertext = input.slice(16); var output; if (isString) { output = decipher.update(ciphertext) + decipher.final(); } else { output = Buffer.concat([decipher.update(ciphertext), decipher.final()]); } return output; }
  3.  
  4.  
  5. const KEY = 'ПРИВАТНЫЙ_КЛЮЧ';
  6. const SALT = 'КЛЮЧ_ДЛЯ_РАСШИФРОВКИ';
  7.  
  8.  
  9. console.log('Приватный ключ - ');
  10. console.log(decrypt(SALT,KEY))
Add Comment
Please, Sign In to add comment