/** * @param privateKeyPEM * RSA private key in PEM format * @param fingerprint * ex. {@code 2b:a9:62:95:5b:8b:1d:61:e0:92:f7:03:10:e9:db:d9} * @return true if the keypair has the same fingerprint as supplied */ public static boolean privateKeyHasFingerprint(String privateKeyPEM, String fingerprint) { KeySpec privateKeySpec = privateKeySpec(privateKeyPEM); checkArgument(privateKeySpec instanceof RSAPrivateCrtKeySpec, "incorrect format expected RSAPrivateCrtKeySpec was %s", privateKeySpec); return privateKeyHasFingerprint(RSAPrivateCrtKeySpec.class.cast(privateKeySpec), fingerprint); }
/** * @param privateKeyPEM * RSA private key in PEM format * @param fingerprint * ex. {@code 2b:a9:62:95:5b:8b:1d:61:e0:92:f7:03:10:e9:db:d9} * @return true if the keypair has the same fingerprint as supplied */ public static boolean privateKeyHasFingerprint(String privateKeyPEM, String fingerprint) { KeySpec privateKeySpec = privateKeySpec(privateKeyPEM); checkArgument(privateKeySpec instanceof RSAPrivateCrtKeySpec, "incorrect format expected RSAPrivateCrtKeySpec was %s", privateKeySpec); return privateKeyHasFingerprint(RSAPrivateCrtKeySpec.class.cast(privateKeySpec), fingerprint); }
/** * @param privateKeyPEM * RSA private key in PEM format * @param fingerprint * ex. {@code 2b:a9:62:95:5b:8b:1d:61:e0:92:f7:03:10:e9:db:d9} * @return true if the keypair has the same fingerprint as supplied */ public static boolean privateKeyHasFingerprint(String privateKeyPEM, String fingerprint) { KeySpec privateKeySpec = privateKeySpec(privateKeyPEM); checkArgument(privateKeySpec instanceof RSAPrivateCrtKeySpec, "incorrect format expected RSAPrivateCrtKeySpec was %s", privateKeySpec); return privateKeyHasFingerprint(RSAPrivateCrtKeySpec.class.cast(privateKeySpec), fingerprint); }
/** * @param privateKeyPEM * RSA private key in PEM format * @param fingerprint * ex. {@code 2b:a9:62:95:5b:8b:1d:61:e0:92:f7:03:10:e9:db:d9} * @return true if the keypair has the same fingerprint as supplied */ public static boolean privateKeyHasFingerprint(String privateKeyPEM, String fingerprint) { KeySpec privateKeySpec = privateKeySpec(privateKeyPEM); checkArgument(privateKeySpec instanceof RSAPrivateCrtKeySpec, "incorrect format expected RSAPrivateCrtKeySpec was %s", privateKeySpec); return privateKeyHasFingerprint(RSAPrivateCrtKeySpec.class.cast(privateKeySpec), fingerprint); }
@Test public void testPrivateKeyMatchesFingerprintString() throws IOException { String privKey = Strings2.toStringAndClose(getClass().getResourceAsStream("/test")); assert privateKeyHasFingerprint(privKey, expectedFingerprint); }
@Test public void testPrivateKeyMatchesFingerprintString() throws IOException { String privKey = Strings2.toStringAndClose(getClass().getResourceAsStream("/test")); assert privateKeyHasFingerprint(privKey, expectedFingerprint); }
@Test public void testPrivateKeyMatchesFingerprintTyped() throws IOException { String privKey = Strings2.toStringAndClose(getClass().getResourceAsStream("/test")); RSAPrivateCrtKeySpec privateKey = (RSAPrivateCrtKeySpec) Pems.privateKeySpec(privKey); assert privateKeyHasFingerprint(privateKey, expectedFingerprint); }
@Test public void testPrivateKeyMatchesFingerprintTyped() throws IOException { String privKey = Strings2.toStringAndClose(getClass().getResourceAsStream("/test")); RSAPrivateCrtKeySpec privateKey = (RSAPrivateCrtKeySpec) Pems.privateKeySpec(privKey); assert privateKeyHasFingerprint(privateKey, expectedFingerprint); }
assert SshKeys.privateKeyHasFingerprint(result.getKeyMaterial(), result.getFingerprint());
assert SshKeys.privateKeyHasFingerprint(result.getKeyMaterial(), result.getFingerprint());