very good
I have been working on a desktop application that connects to an access 2016 database to save some data, everything has gone great, but I need the database to be encrypted to prevent them from freely modifying the data.
I have started to investigate how I can achieve this, I am working with UCanAccess-5.0.0, according to what I have read, the connection string changes and now an encryption class is necessary.
I started working with jackcess-encrypt-4.0.2 but I'm getting some errors and I would like to know if you can help me, I appreciate any help.
I am working with netbeans 12.5 and I am running with java witch ant and jdk 8.
This is my connection class:
package Class;
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
public class Conn {
Connection cn = null;
Statement st = null;
public Connection(){
try {
String rutafile = "C:\\Users\\Ramej\\Documents\\Projects\\Test\\DB_Q2.accdb;jackcessOpener=Class.CryptCodecOpener";
String url = "jdbc:ucanaccess://" + rutafile;
cn = DriverManager.getConnection(url,"sa","123");
st = cn.createStatement();
} catch (SQLException e) {
System.err.println("Error: " + e);
}
}
public Connection getConnection(){
return cn;
}
public void Disconnection(){
try {
cn.close();
} catch (SQLException e) {
Logger.getLogger(Conexion.class.getName()).log(Level.SEVERE, null, e);
System.err.println("Error: "+ e);
}
}
}
and I have the CryptCodecOpener class set up as follows:
package Class;
import com.healthmarketscience.jackcess.Database;
import com.healthmarketscience.jackcess.DatabaseBuilder;
import com.healthmarketscience.jackcess.crypt.CryptCodecProvider;
import java.io.File;
import java.io.IOException;
import net.ucanaccess.jdbc.JackcessOpenerInterface;
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();
}
}
When entering the system and connecting to the database I find the following errors:
Exception in thread "AWT-EventQueue-0" java.lang.IllegalAccessError: tried to access field com.healthmarketscience.jackcess.impl.PageChannel.DEFAULT_BYTE_ORDER from class com.healthmarketscience.jackcess.crypt.impl.BaseCryptCodecHandler
at com.healthmarketscience.jackcess.crypt.impl.BaseCryptCodecHandler.wrap(BaseCryptCodecHandler.java:349)
at com.healthmarketscience.jackcess.crypt.impl.OfficeCryptCodecHandler.create(OfficeCryptCodecHandler.java:81)
at com.healthmarketscience.jackcess.crypt.CryptCodecProvider.createHandler(CryptCodecProvider.java:130)
at com.healthmarketscience.jackcess.impl.PageChannel.initialize(PageChannel.java:105)
at com.healthmarketscience.jackcess.impl.DatabaseImpl.<init>(DatabaseImpl.java:554)
at com.healthmarketscience.jackcess.impl.DatabaseImpl.open(DatabaseImpl.java:415)
at com.healthmarketscience.jackcess.DatabaseBuilder.open(DatabaseBuilder.java:267)
at Clases.CryptCodecOpener.open(CryptCodecOpener.java:27)
at net.ucanaccess.jdbc.DBReference.<init>(DBReference.java:170)
at net.ucanaccess.jdbc.DBReferenceSingleton.loadReference(DBReferenceSingleton.java:51)
at net.ucanaccess.jdbc.UcanaccessDriver.connect(UcanaccessDriver.java:91)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
at Clases.Conexion.<init>(Conexion.java:34)
at Ventana.MenuPrincipal.<init>(MenuPrincipal.java:66)
at Ventana.MenuPrincipal$11.run(MenuPrincipal.java:511)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)
I have tried to run with jackcess-encrypt-4.0.2 and with jackcess-encrypt-2.1.0 without getting any different result, I have also tried with bcprov-debug-jdk18on-172, bcprov-ext-jdk15on -1.70, bcprov-ext-jdk18on-172. Without finding a solution. I guess I'm not loading any other library or I don't know what I'm doing wrong, I appreciate the help.
Ok, indeed as I suspected my problem was about incompatibility with the libraries, don't take into account that
jackcess-encryptandbcprovmust not only be compatible with each other, but must also be compatible with the version ofUCanAccessthat you are using, in addition to obviously the version of java.I had a hard time finding a combination of versions that worked for me for java 1.8, the one I got was:
ucanaccess-3.0.3.1,jackcess-encrypt-2.1.1, andbcprov-jdk15on-154However I would like to get it to work with
UCanAccess-5.0.1but I just get errors and errors again when I try, if anyone knows how to do this I would appreciate the help.