Monday, May 7, 2018

litteral search with encrypted data with MYSQL database

Leave a Comment

I use these functions to encrypt / decrypt my data in MySQL Database:

'use strict';  const crypto = require('crypto');  const ENCRYPTION_KEY = process.env.ENCRYPTION_KEY; // Must be 256 bytes (32 characters) const IV_LENGTH = 16; // For AES, this is always 16  function encrypt(text) {   let iv = crypto.randomBytes(IV_LENGTH);   let cipher = crypto.createCipheriv('aes-256-cbc', new Buffer(ENCRYPTION_KEY), iv);   let encrypted = cipher.update(text);    encrypted = Buffer.concat([encrypted, cipher.final()]);    return iv.toString('hex') + ':' + encrypted.toString('hex'); }  function decrypt(text) {   let textParts = text.split(':');   let iv = new Buffer(textParts.shift(), 'hex');   let encryptedText = new Buffer(textParts.join(':'), 'hex');   let decipher = crypto.createDecipheriv('aes-256-cbc', new Buffer(ENCRYPTION_KEY), iv);   let decrypted = decipher.update(encryptedText);    decrypted = Buffer.concat([decrypted, decipher.final()]);    return decrypted.toString(); }  module.exports = { decrypt, encrypt }; 

(from this link)

Now, I'd like to do a litteral search from my database. What is the best way to do it?

For example, I store encrypted names in my database but i'd like to be able to search lines with specific names.

0 Answers

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment