How to get fixed value for encryption the same string ? #3911
Unanswered
3adel-bassiony
asked this question in
Help
Replies: 2 comments 8 replies
-
Hey @3adel-bassiony! 👋🏻 What is the issue of having a different value each time you encrypt something? This is because the input is salted to add another security level on top of the encryption. |
Beta Was this translation helpful? Give feedback.
2 replies
-
You can try something like: const KEY = 'random-fixed-key';
const IV = 'random-fixed-iv';
public static encrypt(input: string): string {
const aesCipher = crypto.createCipheriv('aes-256-cbc', Buffer.from(KEY), Buffer.from(IV));
return aesCipher.update(input, 'utf8', 'hex') + aesCipher.final('hex');
}
public static decrypt(hash: string): string {
const aesDecipher = crypto.createDecipheriv('aes-256-cbc', Buffer.from(KEY), Buffer.from(IV));
return aesDecipher.update(hash, 'hex', 'utf8') + aesDecipher.final('utf8');
} Please note, that this isn't as secure though. |
Beta Was this translation helpful? Give feedback.
6 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello
I checked the encryption part in adonis.js but I can't find a way to encrypt something with a static key.
I mean I want to encrypt the users emails and usernames in the database and I tried to use the encryption in adonis.js but every time I try to encrypt I got a different value, so how I can encrypt them and get the same value or how I can use a specific key for each user ? something like a password for every user and he can only decrypt or encrypt his data?
Also, I tried to use a custom secret key but still got different values.
https://docs.adonisjs.com/guides/security/encryption#encryptingdecrypting-values
Beta Was this translation helpful? Give feedback.
All reactions