Can't insert SHA3-256 from runscript

90 views
Skip to first unread message

nicolas duminil

unread,
Oct 2, 2022, 10:53:16 AM10/2/22
to H2 Database
Hello,

Running the following insert statement in the H2 console:

INSERT INTO mytable VALUES(hash ('SHA3-256', X'0102'));

works as expected. However, running the same statement in a script used in the JDBC connection string, as follows:

    @DataSourceDefinition(
     name = "java:global/H2",
     className = "org.h2.jdbcx.JdbcDataSource",
     url = "jdbc:h2:mem:test;DB_CLOSE_ON_EXIT=FALSE;INIT=runscript from '~/init.sql'"

raises the following exception:

    Caused by: com.sun.appserv.connectors.internal.api.PoolingException: Connection could not be allocated because: Invalid value "SHA3-256" for parameter "algorithm"; SQL statement:
 
     INSERT INTO caller VALUES(HASH ('SHA3-256',X'0102')) [90008-200]

What should I do such that  the same SQL statement works the same whether ran in the console or in a Java class ?

Many thanks in advance.

Nicolas

Evgenij Ryazanov

unread,
Oct 2, 2022, 11:19:10 AM10/2/22
to H2 Database
Hello.

SHA3-256 is only supported by H2 2.*.*. Error code 90008-200 was produced by H2 1.4.200, it doesn't support that algorithm. You need to upgrade H2 used by your application to a some recent version.

Christian Buchegger

unread,
Oct 3, 2022, 8:05:42 AM10/3/22
to h2-da...@googlegroups.com
Check the classpath of your script. The -200 in the exception indicates the error was produced by the old version of h2.

 

nicolas duminil

unread,
Oct 3, 2022, 1:44:44 PM10/3/22
to H2 Database
Hello,

Many thanks for this information. My application deploys on Payara platform which already includes H2 1.4.200. Since trying to use another more recent release raises Java class loading issues, I could keep using this one. But then I don't know what algorithm to use for the HASH function. I tried, for example, HASH ('SHA-1','password') but it isn't supported neither. I even tried MD5 with the same result. What are the algorithms supported by 1.4.200 since I could use anyone ?

Many thanks in advance.

Evgenij Ryazanov

unread,
Oct 3, 2022, 9:45:52 PM10/3/22
to H2 Database
H2 1.4.200 supports only SHA-256 and it needs to be specified as SHA256 (without dash) in this outdated version.

Please note that passwords should normally be hashed with a random data (salt) to prevent some common attacks.
Reply all
Reply to author
Forward
0 new messages