我有一个ms访问数据库"abc.accdb",密码为"abcdabcdef"。尝试通过以下命令用Jackcess Encrypt打开它:
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"));
}
}
}
我得到以下异常:
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)
我应该如何打开我的数据库文件?对于"密钥大小超出允许范围"的异常情况,是否有解决方法?请记住,我不允许更改文件的密码。
Database db = new DatabaseBuilder(myDbFile).setCodecProvider(new CryptCodecProvider("MyDbPassword")).open();
使用中提到的上述代码http://jackcessencrypt.sourceforge.net.这可能会奏效。