I am trying to encrypt user input and compare with the encrypted string in database in dialogflow.
How can I add in the crypto package into package.json and get the SHA-224 to work in the index.js? I have tried my code but nothing happened.
Python code to encrypt data for comparison later:
import hashlib
import pandas as pd
strings = []
data = pd.read_csv("DBDATA.csv")
df = data[['ID']]
for index, row in df.iterrows():
b = row["ID"].encode('utf-8')
print(b)
hashed = hashlib.sha224(b).hexdigest()
strings.append(hashed)
data["NUMBER"] = strings
Javascript code to encrypt user input:
const crypto = require('crypto');
var hash = crypto.createHash('sha224');
var string = agent.parameters.adminnumber;
var hashedString = hash.update(string, 'utf-8');
var gen_hash= hashedString.digest('hex');
Package.json
"dependencies": {
"crypto": "4.0.0"
}
The code work well for me (using a hardcoded "string" var). Maybe you don't see anything because you don't log the result.
Remember install the crypto
package using npm install crypto --save
command or just npm install
if dependency already exists into package.json
file.
const crypto = require('crypto');
const hash = crypto.createHash('sha224');
const string = "Test SHA-224 crypto.";
const hashedString = hash.update(string, 'utf-8');
const gen_hash= hashedString.digest('hex');
console.log(gen_hash); // Trace the result
Note: var
keyword makes the baby jesuschrist cry