// IDEA FROM: https://stackoverflow.com/questions/33929712/crypto-in-nodejs-and-ruby var crypto = require('crypto'), algorithm = 'aes-256-cbc', key = 'SOME_RANDOM_KEY_32_CHR_123456789', // 32 Characters iv = "0000000000000000"; // 16 Characters function encrypt(text){ var cipher = crypto.createCipheriv(algorithm,key,iv) var crypted = cipher.update(text,'utf-8',"base64") crypted += cipher.final("base64"); return crypted; } function decrypt(text) { var cipher = crypto.createDecipheriv(algorithm,key,iv) var crypted = cipher.update(text, "base64", "utf-8") crypted += cipher.final("utf-8"); return crypted; } console.log(encrypt("1")); // return KAZL9qez4T7DblhCESPyPA== console.log(decrypt("KAZL9qez4T7DblhCESPyPA==")); // return 1