Hi,
I am syncing Data from Oracle DB to Singlestore for reporting thru Kafka. There are a few fields which needs to be encrypted before sending to Kafka. So trying to encrypt the field using AES128 bit encryption method in a Java program and load the data in Singlestore.
Now, I am unable to decrypt the data in Singlestore which was encrypted with same AES128 bit mechanism using the Java program.
Here is the Java code for AES128 bit encryption.
private static final String encryptionKey = “A1A2A3A4A5A6CAFE”;
private static final String characterEncoding = “UTF-8”;
private static final String cipherTransformation = “AES/ECB/PKCS5PADDING”;
private static final String aesEncryptionAlgorithem = “AES”;
/**
* Method for Encrypt Plain String Data
* @param plainText
* @return encryptedText
*/
public static String encrypt(String plainText) {
String encryptedText = "";
try {
Cipher cipher = Cipher.getInstance(cipherTransformation);
byte[] key = encryptionKey.getBytes(characterEncoding);
SecretKeySpec secretKey = new SecretKeySpec(key, aesEncryptionAlgorithem);
cipher.init(Cipher.ENCRYPT_MODE, secretKey);
byte[] cipherText = cipher.doFinal(plainText.getBytes("UTF-8"));
Base64.Encoder encoder = Base64.getEncoder();
encryptedText = encoder.encodeToString(cipherText);
} catch (Exception E) {
System.err.println("Encrypt Exception : "+E.getMessage());
}
return encryptedText;
}