I have a Java app (not written by me) which uses javax.crypto to encrypt and decrypt file.

Code:
    public static final String PROVIDER = "BC";
    public static final int SALT_LENGTH = 32;
    public static final int IV_LENGTH = 16;
    public static final int PBE_ITERATION_COUNT = 2048;


    private static final String RANDOM_ALGORITHM = "SHA1PRNG";
    private static final String HASH_ALGORITHM = "SHA-512";
    private static final String PBE_ALGORITHM = "PBEWithSHA256And256BitAES-CBC-BC";
    private static final String CIPHER_ALGORITHM = "AES/CBC/PKCS7Padding";
    private static final String SECRET_KEY_ALGORITHM = "AES";
    
    private static final int VERSION = 1;
    private static final String HEADER = "SCAES";


    private byte[] iv = new byte[IV_LENGTH];
    private byte[] salt = new byte[SALT_LENGTH];
    private int currentVersion = 1;


    private static SecretKey getSecretKey(String password, byte[] salt) throws AESCryptException {
        try {
            PBEKeySpec pbeKeySpec = new PBEKeySpec(password.toCharArray(), salt, PBE_ITERATION_COUNT, 256);
            SecretKeyFactory factory = SecretKeyFactory.getInstance(PBE_ALGORITHM, PROVIDER);
            SecretKey tmp = factory.generateSecret(pbeKeySpec);
            return new SecretKeySpec(tmp.getEncoded(), SECRET_KEY_ALGORITHM);
        }
        catch (Exception e) {
            throw new AESCryptException("Unable to get secret key");
        }
    }
The Java app takes an input pwd, compute the sha-512 of the pwd and then uses the aforementioned hash as password for the derivation function.
An encrypted file has the following structure:
IV-SALT-CIPHERTEXT where IV is 16 bytes and SALT is 32 bytes.


I want to develop a C application using Gcrypt which is able to decrypt file encrypted by the above Java app.
I'm very familiar with Gcrypt because I've developed various software with it but, on the other side, I'm not familiar neither with Java nor with javax.crypto.
I setup my C program like this:


Code:
unsigned char iv[16];
    unsigned char salt[32];
    input_key = sha512(user password); //input_key is 128 bytes long because I'm using the hex digest as the java app is doing
    algo = gcry_cipher_map_name("aes256");
    derived_key = gcry_malloc_secure(32);
    gcry_cipher_open(&hd, algo, GCRY_CIPHER_MODE_CBC, 0);
    gcry_kdf_derive (input_key, pwd_len, GCRY_KDF_PBKDF2, GCRY_MD_SHA256, salt, 32, 2048, 32, derived_key)
    gcry_cipher_setkey(hd, derived_key, keyLength);
    gcry_cipher_setiv(hd, iv, blkLength);
    //decrypt and check pkcs_7

but I'm not able to obtain the original file. What am I missing?


Debugging the Java app I understood that the problem should be with the derivation function. Both my C sw and the Java app have the same IV, SALT and PWD (before deriving it).
The only difference is that the pwd aren't the same after the derivation function has been applied.
Any suggestion?