1

I have a decryption problem on a text attribute encoded with java code configured as follows:

private static final String CIPHER_INSTANCE_NAME = "AES/CBC/PKCS5Padding";
private static final String SECRET_KEY_ALGORITHM = "AES";

public Cipher prepareAndInitCipher(int encryptionMode, String key) throws InvalidKeyException, NoSuchPaddingException, NoSuchAlgorithmException, InvalidAlgorithmParameterException {
    Cipher cipher = Cipher.getInstance(CIPHER_INSTANCE_NAME);
    Key secretKey = new SecretKeySpec(key.getBytes(), SECRET_KEY_ALGORITHM);
    AlgorithmParameterSpec algorithmParameters = getAlgorithmParameterSpec(cipher);

    callCipherInit(cipher, encryptionMode, secretKey, algorithmParameters);
    return cipher;
}

Now the problem is that when you launch a query on PgAdmin, the field in question is encrypted. I tried to decrypt it in the following way:

pgp_sym_decrypt(your_table.your_bytea_column , '".$key."', 'compress-algo=1, cipher-algo=aes256')

but I get the following response: 'ERROR: Wrong key or corrupt data SQL state: 39000'

Can someone help me? Thanks.

  • Is Java's encryption compatible with PGP? That is what PostgreSQL is compatible with. – jjanes Dec 09 '21 at 20:10
  • It's not. Well, not `Cipher` anyway, there's the PGP package in Bouncy Castle that uses the ciphers. PGP is a container format, it doesn't directly or only use AES-CBC. – Maarten Bodewes Dec 11 '21 at 01:32

0 Answers0