Search code examples
node.jsencryptionnode-crypto

Node.js Crypto encrypt with -nosalt option


From this post: What's wrong with nodejs crypto decipher? I figured out that to make my code work I need to encrypt my data with the openSSL -nosalt option beacuase of the way the node.js crypto library works. Since I am using the Node.js crypto library to encrypt, I need to know how to encrypt the data with the -nosalt option. Also I am using the openSSL aes256 algorithm.

Thanks,
Ari


Solution

  • The linked question has how to decrypt:

    var crypto=require('crypto')
    var cipher=crypto.createDecipher('aes-256-cbc', "password")
    var enc = cipher.update("Mh5yxIyZH+fSMTkSgkLa5w==", 'base64', 'utf8')
    enc += cipher.final('utf8')
    

    Encrypting is literally the exact opposite.

    var crypto=require('crypto')
    var cipher=crypto.createCipher('aes-256-cbc', "password")
    var enc = cipher.update("owlstead\n", 'binary', 'base64')
    enc += cipher.final('base64')