0

I need to fix the problem of

SecurityException: Can not initialize cryptographic mechanism

Following up on OpenJDK 11 error "Can not initialize cryptographic mechanism", as its answer is unable to solve my problem

inspecting java.security.properties from within running JVM:

    System.getProperty("java.security.properties");

It should be present and pointing at a file. Inspect that file and make sure it has the following property crypto.policy=unlimited and the folder called unlimited is available from where the policy file is.

However, I got null output for both java under Windows and Linux.

The above answer said that

it is <jre_home>/conf/security/policy/

and my situation is that I don't have jre however I do have the /conf/security/policy/ directory under java_home, for both java under Windows and Linux.

 Directory of C:\Program Files\OpenJDK\jdk-18.0.1.1\conf\security\policy

04/25/2022  04:59 PM    <DIR>          .
04/25/2022  04:59 PM    <DIR>          ..
04/25/2022  04:59 PM    <DIR>          limited
04/25/2022  04:59 PM             2,390 README.txt
04/25/2022  04:59 PM    <DIR>          unlimited
               1 File(s)          2,390 bytes
$ ls -l /home/foo/.sdkman/candidates/java/17.0.3-oracle/conf/security/policy
total 4
-rw-r----- 1 foo foo 2390 2022-03-09 17:40 READfoo.txt
drwxrwx--x 1 foo foo 4096 2022-06-03 12:45 limited
drwxrwx--x 1 foo foo 4096 2022-06-03 12:45 unlimited
xpt
  • 20,363
  • 37
  • 127
  • 216

1 Answers1

0

See Cryptographic Strength Configuration ...and build the path with $JAVA_HOME.

On Linux the default paths are:

  • JDK8: $JAVA_HOME/jre/lib/security/java.security
  • JDK11: $JAVA_HOME/conf/security
  • JDK14: $JAVA_HOME/conf/security, mostly sym-linked to /etc/java-14-openjdk/security.

"Jurisdiction Policy File" java.security should have crypto.policy = unlimited set from JDK9 onwards; policies can be found $JAVA_HOME/conf/security/unlimited/default_US_export.policy.

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
  • So my files are at the proper place, but why the output of `System.getProperty("java.security.properties")` is `null` for both java under Windows and Linux? – xpt Jun 03 '22 at 22:33
  • That other answer runs with `java -D...` ...and this sets the property. Why not `System.getProperty("java.home")`?? – Martin Zeitler Jun 03 '22 at 22:37
  • I need to fix "Can not initialize cryptographic mechanism" which requires System.getProperty("java.security.properties") _"be present and pointing at a file. "_. Printing java.home won't help. How to let System.getProperty("java.security.properties") pointing to the proper file? – xpt Jun 03 '22 at 23:18
  • I downgraded my Java from V18 to V11 and the "Can not initialize cryptographic mechanism" just gone. – xpt Jun 04 '22 at 13:10