I ran into an issue with my server that made me ask a question - is AES-256 encryption reliably consistent?
So my node server, to avoid DDOS vulnerabilities while keeping user data anonymous, takes an IP from the request, encrypts it, and stores the number of times it has made a request in the last 24 hours.
It checks if the user had made a request in the last 24 hours by re-encrypting the IP using the exact same password. It then, takes that and matches it with the first stored IP.
But then:
Error: Can't find data: /ipcount/d00c526612cec9e5d3e201af35993c75. Stopped at ipcount
d00c526612cec9e5d3e201af35993c75
should be the encrypted string, but the database is acting like it's never seen it before. So can I have it encrypt consistently with the same password?
Thanks in advance.
Here is the encryption function...
const crypto = require('crypto'),
algorithm = 'aes-256-ctr',
password = 'aSecureNotSharedOverAForumPassword'
function encrypt(text){
var cipher = crypto.createCipher(algorithm,password)
var crypted = cipher.update(text,'utf8','hex')
crypted += cipher.final('hex');
return crypted;
}