diff --git a/iot/api-client/mqtt_example/src/main/java/com/google/cloud/iot/examples/MqttExample.java b/iot/api-client/mqtt_example/src/main/java/com/google/cloud/iot/examples/MqttExample.java index 8eb34750586..91e8c2246cc 100644 --- a/iot/api-client/mqtt_example/src/main/java/com/google/cloud/iot/examples/MqttExample.java +++ b/iot/api-client/mqtt_example/src/main/java/com/google/cloud/iot/examples/MqttExample.java @@ -53,7 +53,7 @@ private static String createJwtRsa(String projectId, String privateKeyFile) thro byte[] keyBytes = Files.readAllBytes(Paths.get(privateKeyFile)); PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(keyBytes); - KeyFactory kf = KeyFactory.getInstance("RSA256"); + KeyFactory kf = KeyFactory.getInstance("RSA"); return jwtBuilder.signWith(SignatureAlgorithm.RS256, kf.generatePrivate(spec)).compact(); } @@ -107,10 +107,11 @@ public static void main(String[] args) throws Exception { // to authorize the device. connectOptions.setUserName("unused"); - if (options.algorithm == "RSA256") { + System.out.println(options.algorithm); + if (options.algorithm.equals("RS256")) { connectOptions.setPassword( createJwtRsa(options.projectId, options.privateKeyFile).toCharArray()); - } else if (options.algorithm == "ES256") { + } else if (options.algorithm.equals("ES256")) { connectOptions.setPassword( createJwtEs(options.projectId, options.privateKeyFile).toCharArray()); } else {