How to Hash password and Encrypt Database in H2

1,380 views
Skip to first unread message

Abdul Jabbar WebBestow

unread,
Nov 8, 2014, 11:40:39 AM11/8/14
to h2-da...@googlegroups.com

I have an application with H2 for Database. I am facing difficulities in securing my H2 Database to least possible extent. I got 2 questions

First Question

To Hash database password, I read Documents of H2 here at http://www.h2database.com/html/advanced.html but could not understand how can I hash my database password. As the Document states

"To calculate the password hash from a plain text password, run the following command within the H2 Console tool": e.g.: @password_hash SA test

but as I go to my H2 Console Tool (command line) it opens up browser with its GUI console and there I cannot find anything where I can run such command (@password_hash SA test) to Hash my password.



Second Question

2) To Encrypt Database I read this H2 Document at http://h2database.com/html/features.html#file_encryption it suggest this code to Encrypt Database

Class.forName("org.h2.Driver");
String url = "jdbc:h2:~/test;CIPHER=AES";
String user = "sa"; 
String pwds = "filepwd userpwd";
conn = DriverManager.
getConnection(url, user, pwds);

To Encrypt Database, do I just have to include CIPHER=AES and password with DB password and that's all? will this Encrypt Database then?

Thomas Mueller

unread,
Nov 10, 2014, 5:17:29 AM11/10/14
to h2-da...@googlegroups.com
Hi,

This question is answered on StackOverflow.com.

Regards,
Thomas
--
You received this message because you are subscribed to the Google Groups "H2 Database" group.
To unsubscribe from this group and stop receiving emails from it, send an email to h2-database...@googlegroups.com.
To post to this group, send email to h2-da...@googlegroups.com.
Visit this group at http://groups.google.com/group/h2-database.
For more options, visit https://groups.google.com/d/optout.

Arda Orhan

unread,
Nov 10, 2014, 6:38:48 AM11/10/14
to h2-da...@googlegroups.com
Hi jabbar,

For your second question. In your code example database will be created with admin username: sa and pass: filepwd and your database will be encrypted with userpwd. So when you change  your "userpwd" to "blabla", even you give true admin password, bcoz of your database encrypted you wouldn't get any connection. 

Dont forget! Database is created at your first attempt. DB name will be "test". After first connection, your all connection attempt should have same passwords!
Reply all
Reply to author
Forward
0 new messages