Advertisement
vitareinforce

encrypt

Jan 31st, 2019
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. const Crypto = require('crypto');
  2.  
  3. module.exports = {
  4.  
  5. decryptedText : function (text) {
  6. // we compute the sha256 of the key
  7. var hash = Crypto.createHash("md5");
  8. hash.update('pptik2018', "utf8");
  9. var sha128key = hash.digest();
  10. var keyBuffer = new Buffer(sha128key);
  11.  
  12. var cipherBuffer = new Buffer(text, 'hex');
  13. // always use createDecipheriv when the key is passed as raw bytes
  14. var aesDec = Crypto.createDecipheriv("aes-128-ecb", keyBuffer , '');
  15. var output = aesDec.update(cipherBuffer);
  16. return output + aesDec.final();
  17. },
  18. encryptedText : function (text) {
  19. var cipher = Crypto.createCipher('aes-128-ecb','pptik2018');
  20. var crypted = cipher.update(text.toString(),'utf-8','hex');
  21. crypted += cipher.final('hex')
  22. return crypted;
  23. }
  24. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement