简体   繁体   English

我正在尝试使用提供的示例“ SendEventX509.java”发送消息,但我遇到了问题。 下面提到的Stacktrace

[英]I am trying send message using provided sample “SendEventX509.java” but I am facing issue. Stacktrace mentioned below

I am trying send message using provided sample "SendEventX509.java" but I am facing issue. 我正在尝试使用提供的示例“ SendEventX509.java”发送消息,但我遇到了问题。 Stacktrace mentioned below OS - Windows 10 下面提到的Stacktrace OS-Windows 10

Java runtime used: JDK 11.0.3 使用的Java运行时:JDK 11.0.3

SDK version used: IoT Hub Java Device SDK 1.17.5 使用的SDK版本:IoT中心Java设备SDK 1.17.5

Sample provided in " 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 " 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

The certificates have been generated from "ProvisioningX509CertGen.java" and device has been successfully enrolled and provisioned in IoTHub with X509 attestation. 证书已从“ ProvisioningX509CertGen.java”生成,并且设备已成功注册并通过X509证明在IoTHub中提供。

Console log of the issue: 问题的控制台日志:

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

Please help to resolve this issue 请帮助解决此问题

The default keystore type has changed from jks to pkcs12 since Java 9. It seems the above azure SDK code works properly with JKS keystore. 自Java 9以来,默认的密钥库类型已从jks更改为pkcs12。似乎以上的Azure SDK代码可与JKS密钥库一起正常使用。 You have two options: 您有两种选择:

  1. Change the keystore.type to jks in java.security file in your Java 11 jdk/jre installation. 将Java 11 jdk / jre安装中的java.security文件中的keystore.type更改为jks。 This will have wider impact on all applications. 这将对所有应用程序产生更广泛的影响。 So be careful. 所以要小心

  2. If you have cloned the full repo of azure samples from github, change the com.microsoft.azure.sdk.iot.deps.auth.IotHubSSLContext.generateSSLContextWithKeys() and get instance of JKS keystore instead of default one. 如果您已从github克隆了完整的Azure样本回购,请更改com.microsoft.azure.sdk.iot.deps.auth.IotHubSSLContext.generateSSLContextWithKeys()并获取JKS密钥库的实例,而不是默认实例。 So change: 所以改变:

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

to

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

that should hopefully do the trick for you. 希望可以帮到您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我正在尝试运行以下提到的代码,但出现错误 - I am trying to run the below mentioned code but getting an error 尝试在“ Windows 8.1”操作系统中更新“ Java”时遇到问题 - I am facing issue while trying to update “Java” in “windows 8.1” OS 我在使用 selenium java 在 html5 中拖放时遇到问题 - I am facing issue in drag and drop in html5 with selenium java 我想用java程序发送电子邮件。 我得到如下的豁免权 - I want to send email using java program. I am getting the excetion as below 我在Java中使用stringbuilder csv创建CSV文件时遇到问题 - I am facing an issue in creating CSV File using stringbuilder csv in java 我想使用Java连接到SQL Server,请找到下面的代码,并且出现“错误消息”下方给出的异常 - i want to connect to SQL Server using Java, please find the code below and i am getting the exception as given below “Error Message” 我正在尝试使用 Java 8 在以下代码段中实现策略设计模式。寻找更好的实现方法? - I am trying to implement the strategy design pattern in the below snippet using Java 8 .Looking for better ways to implement? 我在Java中的扫描仪类中遇到问题 - I am Facing issues in Scanner Class in java 我在阅读这个堆栈跟踪信息吗? - Am I reading this stacktrace right? 正则表达式问题。 我究竟做错了什么? - Silly RegEx issue. What am I doing wrong?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM