0

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.

4

0 回答 0