Skip to content

Commit

Permalink
Fixes RSA algo and uses .equals for string comparisons (GoogleCloudPl…
Browse files Browse the repository at this point in the history
  • Loading branch information
gguuss authored and lesv committed Jul 7, 2017
1 parent ead4ce1 commit 50d1969
Showing 1 changed file with 4 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 50d1969

Please sign in to comment.