Connect to a password-protected MS Access db using UCanAccess 5.1.x and Jackcess Encrypt #21
|
I was connecting to a password-protected ACCDB file using UcanAccess 5.0.1 by implementing the JackcessOpenerInterface as follows: import io.github.spannm.jackcess.CryptCodecProvider;
import io.github.spannm.jackcess.Database;
import io.github.spannm.jackcess.DatabaseBuilder;
import net.ucanaccess.jdbc.JackcessOpenerInterface;
import java.io.File;
import java.io.IOException;
public class CryptCodecOpener implements JackcessOpenerInterface {
public Database open(File fl, String pwd) throws IOException {
DatabaseBuilder dbd = new DatabaseBuilder(fl);
dbd.setAutoSync(false);
dbd.setCodecProvider(new CryptCodecProvider(pwd));
dbd.setReadOnly(false);
return dbd.open();
}
}I am attempting to upgrade to UcanAccess 5.1.2. However, since Jackcess has been forked and the package has moved from The interface for
|
Replies: 4 comments 1 reply
|
Hi Takumi, I was wondering whether someone would ask that question :) |
|
Update: I am working on a compatible version of jackcess-encrypt. The artifact has now been released and is available for usage. |
|
If it's done, do you have a simple working example? |
|
Hi everyone 🙋🏼♂️ please find a complete, runnable example for encrypted example/issue-21-password-protection RequirementsTo enable decryption support, ensure you have the <dependency>
<groupId>io.github.spannm</groupId>
<artifactId>jackcess-encrypt</artifactId>
<version>5.1.3</version>
</dependency>Components
package net.ucanaccess.example;
import io.github.spannm.jackcess.Database;
import io.github.spannm.jackcess.DatabaseBuilder;
import io.github.spannm.jackcess.encrypt.CryptCodecProvider;
import net.ucanaccess.jdbc.IJackcessOpenerInterface;
import java.io.File;
import java.io.IOException;
/**
* Custom opener for password-protected databases.
*/
public final class PasswordProtectedOpener implements IJackcessOpenerInterface {
@Override
public Database open(File dbFile, String password) throws IOException {
return new DatabaseBuilder()
.withFile(dbFile)
.withCodecProvider(new CryptCodecProvider(password))
.open();
}
}
Path dbPath = Path.of("src/main/resources/password-protected.accdb");
String password = "alligator3";
String tableName = "t_demo";
String url = String.format("jdbc:ucanaccess://%s;jackcessOpener=%s",
dbPath, PasswordProtectedOpener.class.getName());
LOG.log(Level.INFO, "About to connect to database ''{0}''", dbPath.getFileName());
try (Connection conn = DriverManager.getConnection(url, "user", password)) {
LOG.log(Level.INFO, "Connection to ''{0}'' successful", dbPath.getFileName());
// ... Quick StartSimply run
|
Hi everyone 🙋🏼♂️
please find a complete, runnable example for encrypted
.accdbaccess in this dedicated branch:example/issue-21-password-protection
Requirements
To enable decryption support, ensure you have the
jackcess-encryptextension in yourpom.xml:Components
Implements
IJackcessOpenerInterfaceto provide theCryptCodecProviderwith your password