Jackcess Encrypt gives "key size is outside allowable range" when opening Database with password

463 views Asked by At

I have an ms access database "abc.accdb" which has a password "abcdabcdef". Tried to open it with Jackcess Encrypt via this command:

package com.sample;
import java.io.File;
import java.io.IOException;
import com.healthmarketscience.jackcess.CryptCodecProvider;
import com.healthmarketscience.jackcess.Database;
import com.healthmarketscience.jackcess.DatabaseBuilder;
import com.healthmarketscience.jackcess.Row;
import com.healthmarketscience.jackcess.Table;
import com.healthmarketscience.jackcess.impl.CodecProvider;

public class Test {
    public static void main(String[] args) throws IOException {
        CryptCodecProvider cryptProvider = new CryptCodecProvider("abcdabcdef");
        Database db = new DatabaseBuilder(new File("abc.accdb")).setCodecProvider((CodecProvider) cryptProvider).open();
        Table table = db.getTable("Checklist");
        for(Row row : table) {
          System.out.println("Column 'Company' has value: " + row.get("Company"));
        }
    }
}

I get the following exception:

Exception in thread "main" java.lang.IllegalStateException: com.healthmarketscience.jackcess.impl.office.EncryptionHeader@1af7c57 key size is outside allowable range
    at com.healthmarketscience.jackcess.impl.office.EncryptionHeader.read(EncryptionHeader.java:185)
    at com.healthmarketscience.jackcess.impl.office.RC4CryptoAPIProvider.<init>(RC4CryptoAPIProvider.java:55)
    at com.healthmarketscience.jackcess.impl.OfficeCryptCodecHandler.create(OfficeCryptCodecHandler.java:121)
    at com.healthmarketscience.jackcess.CryptCodecProvider.createHandler(CryptCodecProvider.java:117)
    at com.healthmarketscience.jackcess.impl.PageChannel.initialize(PageChannel.java:120)
    at com.healthmarketscience.jackcess.impl.DatabaseImpl.<init>(DatabaseImpl.java:511)
    at com.healthmarketscience.jackcess.impl.DatabaseImpl.open(DatabaseImpl.java:386)
    at com.healthmarketscience.jackcess.DatabaseBuilder.open(DatabaseBuilder.java:170)
    at com.sample.Test.main(Test.java:14)

How should I open my database file? Is there a workaround for the "key size is outside allowable range" exception? Please keep in mind that I'm not allowed to change the password of the file.

1

There are 1 answers

0
Pramod Kumar Sharma On
Database db = new DatabaseBuilder(myDbFile).setCodecProvider(new CryptCodecProvider("MyDbPassword")).open();

Use above code as mentioned in http://jackcessencrypt.sourceforge.net. This might work.