Nodejs Crypto decrypt fails after one successful encryption and decryption

Alon Carmel

I got a weird scenario on nodejs where crypto works encryption and decryption of text only once when i load the node server. After the second try it encrypts the text fine but is unable to decrypt the text on second try.

This is my code:

function Encrypt(mytext) {
  var cipher = crypto.createCipher('aes-256-cbc','fa97be5d286a67114cf74acf46d179725581d562');
  var crypted = cipher.update(mytext,'utf8','hex');
  crypted += cipher.final('hex');
}

function Decipher(mytext) {
  var decipher = crypto.createDecipher('aes-256-  cbc','fa97be5d286a67114cf74acf46d179725581d562');
  var dec = decipher.update(mytext,'hex','utf8');
  dec += decipher.final('utf8');
}

This works fine ONCE the nodejs server loads, encrypt and decrypts the data perfectly, the second time this function is used elsewhere with a different text or key it fails to decrypt the text. I'm puzzled.

Alon Carmel

This was resolved after i've added:

delete require.cache[require.resolve('./templates/prd')];

The required object stayed in cache and continued to be encrypted over and over. once i cleared the cache everytime i loaded the template it started encrypting it properly.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

nodejs: node module for encryption/decryption?

From Dev

nodejs: node module for encryption/decryption?

From Dev

Compatibility between node crypto and crypto-js encryption and decryption

From Dev

Decryption returns empty result - nodejs crypto

From Dev

attempting to decrypt using crypto-js and nodejs

From Dev

Decrypt secret using ECDH and nodejs crypto

From Dev

Blowfish crypto messes up first 8 bytes during encryption and decryption

From Dev

Blowfish crypto messes up first 8 bytes during encryption and decryption

From Dev

Converting Java Encryption to Javascript with NodeJs Crypto

From Dev

Encryption & Decryption

From Dev

Encryption & Decryption

From Dev

Double encryption / decryption fails but single does not - AES 256 bit

From Dev

Crypto Encryption

From Dev

How to create openssl encryption and decryption equivalent of php code in nodejs application

From Dev

Which algorithm is best for encryption in php and storing in database and then decryption in nodejs

From Dev

Need Help to convert Encryption Blowfish php to Nodejs using crypto

From Dev

Handle successful HTTP promise if one fails in Bluebird

From Dev

Jenkins Build fails after successful build deployment

From Dev

Jenkins slave job fails after successful job

From Dev

Jenkins Build fails after successful build deployment

From Dev

Elasticsearch indexing fails after successful Nutch crawl

From Dev

javax.crypto.BadPaddingException: Decryption error when using Java RSA encryption

From Dev

XOR encryption/decryption when the key is more than one byte long?

From Dev

Is it possible to decrypt one-way encryption? (with real data & encrypted data)

From Dev

Is it possible to decrypt one-way encryption? (with real data & encrypted data)

From Dev

nodejs/Expressjs redirect after successful insertion

From Java

Encryption with PHP and Decryption with Coldfusion

From Dev

Encryption in JavaScript and decryption with PHP

From Dev

performance on encryption and decryption

Related Related

  1. 1

    nodejs: node module for encryption/decryption?

  2. 2

    nodejs: node module for encryption/decryption?

  3. 3

    Compatibility between node crypto and crypto-js encryption and decryption

  4. 4

    Decryption returns empty result - nodejs crypto

  5. 5

    attempting to decrypt using crypto-js and nodejs

  6. 6

    Decrypt secret using ECDH and nodejs crypto

  7. 7

    Blowfish crypto messes up first 8 bytes during encryption and decryption

  8. 8

    Blowfish crypto messes up first 8 bytes during encryption and decryption

  9. 9

    Converting Java Encryption to Javascript with NodeJs Crypto

  10. 10

    Encryption & Decryption

  11. 11

    Encryption & Decryption

  12. 12

    Double encryption / decryption fails but single does not - AES 256 bit

  13. 13

    Crypto Encryption

  14. 14

    How to create openssl encryption and decryption equivalent of php code in nodejs application

  15. 15

    Which algorithm is best for encryption in php and storing in database and then decryption in nodejs

  16. 16

    Need Help to convert Encryption Blowfish php to Nodejs using crypto

  17. 17

    Handle successful HTTP promise if one fails in Bluebird

  18. 18

    Jenkins Build fails after successful build deployment

  19. 19

    Jenkins slave job fails after successful job

  20. 20

    Jenkins Build fails after successful build deployment

  21. 21

    Elasticsearch indexing fails after successful Nutch crawl

  22. 22

    javax.crypto.BadPaddingException: Decryption error when using Java RSA encryption

  23. 23

    XOR encryption/decryption when the key is more than one byte long?

  24. 24

    Is it possible to decrypt one-way encryption? (with real data & encrypted data)

  25. 25

    Is it possible to decrypt one-way encryption? (with real data & encrypted data)

  26. 26

    nodejs/Expressjs redirect after successful insertion

  27. 27

    Encryption with PHP and Decryption with Coldfusion

  28. 28

    Encryption in JavaScript and decryption with PHP

  29. 29

    performance on encryption and decryption

HotTag

Archive