Encryption outside Singlestore DB and Descryption inside singlestore

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;
}

Is it related to the issue identified on your other post?

Nope, the encrypted value seems to be diff b/w the Java approach and singlestore. Also, getting error on calling decrypt.

Do you have a sample java program to encrypt outside Singlestore that can be Decrypted in Singlestore.

Sorry, its an issue from my side and Singlestore is working as expected.

1 Like

Glad to hear it has been resolved Baskar! :tada: Thanks for keeping us updated!