SecurityException:无法初始化加密机制

SecurityException: Can not initialize cryptographic mechanism

我需要解决

的问题

SecurityException: Can not initialize cryptographic mechanism

跟进OpenJDK 11 error "Can not initialize cryptographic mechanism",因为它的答案无法解决我的问题

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.

但是,java 在 Windows 和 Linux 下我得到了 null 输出。

上面的回答是这样说的

<jre_home>/conf/security/policy/

我的情况是我没有 jre 但是我在 java_home 下有 /conf/security/policy/ 目录,java 在 [=39= 下] 和 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

参见 Cryptographic Strength Configuration ...并使用 $JAVA_HOME 构建路径。

在 Linux 上,默认路径是:

  • JDK8:$JAVA_HOME/jre/lib/security/java.security
  • JDK11:$JAVA_HOME/conf/security
  • JDK14:$JAVA_HOME/conf/security,主要是 sym-linked 到 /etc/java-14-openjdk/security

“权限策略文件”java.security 应该从 JDK9 开始设置 crypto.policy = unlimited;可以找到政策 $JAVA_HOME/conf/security/unlimited/default_US_export.policy