Skip to content

Commit 50d1969

Browse files
gguusslesv
authored andcommitted
Fixes RSA algo and uses .equals for string comparisons (GoogleCloudPlatform#745)
1 parent ead4ce1 commit 50d1969

File tree

1 file changed

+4
-3
lines changed
  • iot/api-client/mqtt_example/src/main/java/com/google/cloud/iot/examples

1 file changed

+4
-3
lines changed

iot/api-client/mqtt_example/src/main/java/com/google/cloud/iot/examples/MqttExample.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ private static String createJwtRsa(String projectId, String privateKeyFile) thro
5353

5454
byte[] keyBytes = Files.readAllBytes(Paths.get(privateKeyFile));
5555
PKCS8EncodedKeySpec spec = new PKCS8EncodedKeySpec(keyBytes);
56-
KeyFactory kf = KeyFactory.getInstance("RSA256");
56+
KeyFactory kf = KeyFactory.getInstance("RSA");
5757

5858
return jwtBuilder.signWith(SignatureAlgorithm.RS256, kf.generatePrivate(spec)).compact();
5959
}
@@ -107,10 +107,11 @@ public static void main(String[] args) throws Exception {
107107
// to authorize the device.
108108
connectOptions.setUserName("unused");
109109

110-
if (options.algorithm == "RSA256") {
110+
System.out.println(options.algorithm);
111+
if (options.algorithm.equals("RS256")) {
111112
connectOptions.setPassword(
112113
createJwtRsa(options.projectId, options.privateKeyFile).toCharArray());
113-
} else if (options.algorithm == "ES256") {
114+
} else if (options.algorithm.equals("ES256")) {
114115
connectOptions.setPassword(
115116
createJwtEs(options.projectId, options.privateKeyFile).toCharArray());
116117
} else {

0 commit comments

Comments
 (0)