0

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.

Ashok Goli
  • 5,043
  • 8
  • 38
  • 68
  • 1
    I don't know this API, but have you installed the unlimited crypto jurisdiction files in the specific runtime JRE? Is there maybe a cause given for this exception (have you shown the entire stacktrace?) – Maarten Bodewes Dec 11 '13 at 19:32
  • 1
    @owlstead: Doesn't look it uses the JCE based on the stacktrace. – President James K. Polk Dec 12 '13 at 02:08
  • I'm trying this on a 64-bit system. Does this affect the encryption in any way? – Ashok Goli Dec 12 '13 at 04:28
  • @owlstead I've pasted the entire stack trace is pasted. – Ashok Goli Dec 12 '13 at 12:26
  • 1
    @GregS Depends, it is required to catch the (checked) GeneralSecurityException classes. They may have forgotten to indicate the original exception as the cause. But in either case it requires browsing the source of the RC4 implementation, making it a very localized. Regarding the 32 or 64 bit system: if the library is pure Java then it is *unlikely* to cause problems, but if it uses a native library underneath then anything can happen I suppose. – Maarten Bodewes Dec 12 '13 at 15:52
  • 1
    @owlstead: True, true. If I had to guess (and we do in this case :) ) I'd guess that the key is trivially derived from the string argument to the `CryptCodecProvider` constructor and that it is simply too short. I would guess that each character is converted to byte and that is must be a minimum of 16 in length. – President James K. Polk Dec 13 '13 at 01:26
  • 2
    @GregS Well it is open source and it seems to accept bit ranges from 40 to 128, you can see the exception string even. Gotta sleep. – Maarten Bodewes Dec 13 '13 at 03:26
  • @owlstead: I'm out then. – President James K. Polk Dec 13 '13 at 23:37
  • Is it possible to use/link the open source code of the library in a debugger to see what happens? There is likely nobody here that understands the issue with the library and/or database... Without your setup it may be very hard to replicate the issue... – Maarten Bodewes Dec 13 '13 at 23:53
  • cross posted here https://sourceforge.net/p/jackcessencrypt/discussion/1245598/thread/19b34378/?limit=25 – jtahlborn Dec 14 '13 at 00:58

1 Answers1

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

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

Pitel
  • 5,334
  • 7
  • 45
  • 72