gpt4 book ai didi

java - 我正在尝试使用提供的示例 "SendEventX509.java"发送消息,但我遇到了问题。下面提到的堆栈跟踪

转载 作者:行者123 更新时间:2023-12-02 00:53:32 26 4
gpt4 key购买 nike

我正在尝试使用提供的示例“SendEventX509.java”发送消息,但我遇到了问题。下面提到的堆栈跟踪操作系统 - Windows 10

使用的Java运行时:JDK 11.0.3

使用的 SDK 版本:IoT 中心 Java 设备 SDK 1.17.5

https://github.com/Azure/azure-iot-sdk-java/blob/master/device/iot-device-samples/send-event-x509/src/main/java/samples/com/microsoft/azure/sdk/iot/SendEventX509.java”中提供的示例

证书已从“ProvisioningX509CertGen.java”生成,并且设备已通过 X509 证明在 IoTHub 中成功注册和配置。

问题的控制台日志:

Exception in thread "main" java.io.IOException: Could not open the connection
at com.microsoft.azure.sdk.iot.device.DeviceIO.open(DeviceIO.java:164)
at com.microsoft.azure.sdk.iot.device.InternalClient.open(InternalClient.java:130)
at com.microsoft.azure.sdk.iot.device.DeviceClient.open(DeviceClient.java:317)
at samples.com.microsoft.azure.sdk.iot.SendEventX509.main(SendEventX509.java:136)
Caused by: com.microsoft.azure.sdk.iot.device.exceptions.TransportException: java.io.IOException: java.security.KeyStoreException: Key protection algorithm not found: java.security.UnrecoverableKeyException: Encrypt Private Key failed: password has been cleared
at com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttIotHubConnection.open(MqttIotHubConnection.java:204)
at com.microsoft.azure.sdk.iot.device.transport.IotHubTransport.openConnection(IotHubTransport.java:700)
at com.microsoft.azure.sdk.iot.device.transport.IotHubTransport.open(IotHubTransport.java:280)
at com.microsoft.azure.sdk.iot.device.DeviceIO.open(DeviceIO.java:160)
... 3 more
Caused by: java.io.IOException: java.security.KeyStoreException: Key protection algorithm not found: java.security.UnrecoverableKeyException: Encrypt Private Key failed: password has been cleared
at com.microsoft.azure.sdk.iot.device.auth.IotHubX509SoftwareAuthenticationProvider.getSSLContext(IotHubX509SoftwareAuthenticationProvider.java:66)
at com.microsoft.azure.sdk.iot.device.transport.mqtt.MqttIotHubConnection.open(MqttIotHubConnection.java:125)
... 6 more
Caused by: java.security.KeyStoreException: Key protection algorithm not found: java.security.UnrecoverableKeyException: Encrypt Private Key failed: password has been cleared
at java.base/sun.security.pkcs12.PKCS12KeyStore.setKeyEntry(PKCS12KeyStore.java:704)
at java.base/sun.security.pkcs12.PKCS12KeyStore.engineSetKeyEntry(PKCS12KeyStore.java:601)
at java.base/sun.security.util.KeyStoreDelegator.engineSetKeyEntry(KeyStoreDelegator.java:111)
at java.base/java.security.KeyStore.setKeyEntry(KeyStore.java:1174)
at com.microsoft.azure.sdk.iot.deps.auth.IotHubSSLContext.generateSSLContextWithKeys(IotHubSSLContext.java:208)
at com.microsoft.azure.sdk.iot.deps.auth.IotHubSSLContext.(IotHubSSLContext.java:168)
at com.microsoft.azure.sdk.iot.device.auth.IotHubX509SoftwareAuthenticationProvider.generateSSLContext(IotHubX509SoftwareAuthenticationProvider.java:96)
at com.microsoft.azure.sdk.iot.device.auth.IotHubX509SoftwareAuthenticationProvider.getSSLContext(IotHubX509SoftwareAuthenticationProvider.java:56)
... 7 more
Caused by: java.security.UnrecoverableKeyException: Encrypt Private Key failed: password has been cleared
at java.base/sun.security.pkcs12.PKCS12KeyStore.encryptPrivateKey(PKCS12KeyStore.java:951)
at java.base/sun.security.pkcs12.PKCS12KeyStore.setKeyEntry(PKCS12KeyStore.java:641)
... 14 more
Caused by: java.lang.IllegalStateException: password has been cleared
at java.base/javax.crypto.spec.PBEKeySpec.getPassword(PBEKeySpec.java:196)
at org.bouncycastle.jcajce.provider.symmetric.util.BCPBEKey.getPassword(Unknown Source)
at java.base/com.sun.crypto.provider.PKCS12PBECipherCore.implInit(PKCS12PBECipherCore.java:268)
at java.base/com.sun.crypto.provider.PKCS12PBECipherCore.implInit(PKCS12PBECipherCore.java:379)
at java.base/com.sun.crypto.provider.PKCS12PBECipherCore.implInit(PKCS12PBECipherCore.java:364)
at java.base/com.sun.crypto.provider.PKCS12PBECipherCore$PBEWithSHA1AndDESede.engineInit(PKCS12PBECipherCore.java:473)
at java.base/javax.crypto.Cipher.implInit(Cipher.java:847)
at java.base/javax.crypto.Cipher.chooseProvider(Cipher.java:901)
at java.base/javax.crypto.Cipher.init(Cipher.java:1576)
at java.base/javax.crypto.Cipher.init(Cipher.java:1507)
at java.base/sun.security.pkcs12.PKCS12KeyStore.encryptPrivateKey(PKCS12KeyStore.java:934)
... 15 more

请帮忙解决这个问题

最佳答案

自 Java 9 以来,默认 keystore 类型已从 jks 更改为 pkcs12。 看来上述 azure SDK 代码可以与 JKS keystore 正常工作。您有两个选择:

  1. 将 Java 11 jdk/jre 安装中的 java.security 文件中的 keystore.type 更改为 jks。这将对所有应用程序产生更广泛的影响。所以要小心。

  2. 如果您已从 github 克隆了 azure 示例的完整存储库,请更改 com.microsoft.azure.sdk.iot.deps.auth.IotHubSSLContext.generateSSLContextWithKeys() 并获取 JKS keystore 实例而不是默认 keystore 实例。所以改变:

    KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());

KeyStore keystore = KeyStore.getInstance("jks");

希望这对你有用。

关于java - 我正在尝试使用提供的示例 "SendEventX509.java"发送消息,但我遇到了问题。下面提到的堆栈跟踪,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57839433/

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