I'm working on a web application where customers' sensitive data like name, dob, etc need to encrypt and store in the database.
For this, I'm using crypto encryption in java to encrypt the given text and storing the encrypted value in the database.
The following is the piece of code to encrypt the text
import java.security.Key;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import org.apache.commons.codec.binary.Hex;
String key = "";// key to encrypt/decrypt
String customerName = "customer name";
Key aesKey = generateMySQLAESKey(key,"UTF-8");
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.ENCRYPT_MODE, aesKey);
byte[] encrypted = cipher.doFinal(customerName.getBytes("UTF-8"));
String encrtedName = new String(Hex.encodeHex(encrypted));
// storing this encrtedName as varchar in database
An exact search is done by passing with encrypted value in where clause while querying the data from the database
But how can we perform a wildcard search on encrypted columns?
I'm new to cryptography and encryption methods. Please let me know the best approach for this in Java or Mysql Database
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…