Title: How to search a MySQL database with encrypted fields
Tags: mysql;scala;encryption
Question: I have 4 columns in the table. I stored in encrypted values to encryptemployeesId. Thousands of records is available. I want to display particular record using only employeesId. Kindly help us.
id int
encryptemployeesId varchar
secret_Key varchar
salary varchar
Note: The encrypteemployeesId is Dynamic.
Comment: I using two algorithms for the encryption purpose.
1. AES Algorithm
2. I get Some values using AES then I converted character by character.

Comment: The key purpose is mainly the encryption fields are dynamic. If I use secret_key then only its return correct values.

Comment: What benefit is encrypting and saving the key together?

Comment: What juergen is asking: encryption is mainly used to hide/protect the data from someone. If you store the key with your data (actually: anywhere in your database), it is the equivalent of writing the pincode on your debit card, which only protects you from blind people. If you only want to protect yourself from blind people that don't know (and will not know in the future) anyone that can see and don't own (or will own or build) a machine that can read text from a photo, this would be a possible approach. But usually, it is not. And that is why your bank does not allow it.


Here is another answer: If you have table which stores encrypted ID of the employee then you need the same encrypting algorithm for searching the database.
1) Encrypting Algorithm encrypts your employee ID each time new entry is made in database.
2) Use the Encrypting algorithm in search_employee_by_id() method as:
function search_employee_by_id(int id) {
response = encrypt_algorithm(id); //encrypts emplyoeeid you want to search say 5
query.execute("SELECT * FROM EMPLOYEE where encrypted_id =:encryptemployeesId"); //employee id 5(encrypted) matches any employee with id 5.
Hope this helps
Comment for this answer: Didn't get the result because I can insert two rows with same **employeeId**  like 1 but its store different encryption values. EncryptionValues are **dynamic** @jason

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 1, 'CommentCount': 4, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2017:00:02/13/17', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<mysql><scala><encryption>', 'Title': 'How to search a MySQL database with encrypted fields', 'ViewCount': 243, 'id': 42199677, 'user_AboutMe': None, 'user_AccountId': 8119170.0, 'user_DisplayName': 'Sarathkumar Vulchi', 'user_Reputation': 27.0, 'user_Views': 14.0, 'user_id': 6116528.0}}