I have a function to prepare secret key for encryption and decryption using Java:
public void prepareSecreteKey(String theKey) {
MessageDigest sha = null;
try {
key = theKey.getBytes(StandardCharsets.UTF_8);
sha = MessageDigest.getInstance("SHA-1");
key = sha.digest(key);
System.out.println(new String(key, StandardCharsets.UTF_8));
key = Arrays.copyOf(key, 16);
MessageDigest md = MessageDigest.getInstance("SHA1");
secretKeySpec = new SecretKeySpec(key, "AES");
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
}
However, for the old records from database, I would like to manually encrypt using a MySQL query. I have tried using the query below, but the result is different from the result by the Java application.
select to_base64(aes_encrypt('123456789032', 'aesEncryptionKey'));
Anyone can advise? or is there any other method to encrypt the existing record in database?