gpt4 book ai didi

java - 在 Java 中将 null 传递给 KeyManagerFactory.init() 时使用哪个 keystore ?

转载 作者:行者123 更新时间:2023-11-30 06:13:52 26 4
gpt4 key购买 nike

当我执行以下代码时:

KeyManagerFactory keyManagerFactory = KeyManagerFactory             
.getInstance(KeyManagerFactory.getDefaultAlgorithm());
keyManagerFactory.init(null, null);

然后随后建立 ssl 连接,我在线程“main”javax.net.ssl.SSLHandshakeException 中得到一个 Exception: Received fatal alert: handshake_failure 而不是 NullPointerException 或其他东西。那么使用哪个 keystore ?还是隐藏了 NPE?

最佳答案

null 用作 KeyManagerFactory.init(..., ...) 的 keystore 参数时,不使用 keystore (实际上在内部使用 an empty list ).

没有这样的“隐藏”NullPointerException,也没有理由应该有一个。当然,在此处使用 null 值和空集合会在尝试使用 key 管理器时产生影响,但并非所有 SSL/TLS 连接都需要 keystore (例如,没有客户端证书或匿名密码套件的客户端).

(请注意,尽管 keystore 没有默认值 there is one for the truststore ,因此该默认值将与 TrustManagerFactory.init(null) 一起使用。)

关于java - 在 Java 中将 null 传递给 KeyManagerFactory.init() 时使用哪个 keystore ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31292322/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com