private static String computeFingerprint(PublicKey key) { if (key instanceof RSAPublicKey) { RSAPublicKey rsaKey = (RSAPublicKey) key; return SshKeys.fingerprint(rsaKey.getPublicExponent(), rsaKey.getModulus()); } else { throw new IllegalArgumentException("Only RSA keys are supported"); } }
/** * @return true if the keypair has the same fingerprint as supplied */ public static boolean privateKeyHasFingerprint(RSAPrivateCrtKeySpec privateKey, String fingerprint) { return fingerprint(privateKey.getPublicExponent(), privateKey.getModulus()).equals(fingerprint); }
/** * @return true if the keypair has the same fingerprint as supplied */ public static boolean publicKeyHasFingerprint(RSAPublicKeySpec publicKey, String fingerprint) { return fingerprint(publicKey.getPublicExponent(), publicKey.getModulus()).equals(fingerprint); }
/** * @return true if the keypair has the same fingerprint as supplied */ public static boolean privateKeyHasFingerprint(RSAPrivateCrtKeySpec privateKey, String fingerprint) { return fingerprint(privateKey.getPublicExponent(), privateKey.getModulus()).equals(fingerprint); }
/** * @return true if the keypair has the same fingerprint as supplied */ public static boolean publicKeyHasFingerprint(RSAPublicKeySpec publicKey, String fingerprint) { return fingerprint(publicKey.getPublicExponent(), publicKey.getModulus()).equals(fingerprint); }
/** * @return true if the keypair has the same fingerprint as supplied */ public static boolean privateKeyHasFingerprint(RSAPrivateCrtKeySpec privateKey, String fingerprint) { return fingerprint(privateKey.getPublicExponent(), privateKey.getModulus()).equals(fingerprint); }
/** * @return true if the keypair has the same fingerprint as supplied */ public static boolean publicKeyHasFingerprint(RSAPublicKeySpec publicKey, String fingerprint) { return fingerprint(publicKey.getPublicExponent(), publicKey.getModulus()).equals(fingerprint); }
/** * @return true if the keypair has the same fingerprint as supplied */ public static boolean privateKeyHasFingerprint(RSAPrivateCrtKeySpec privateKey, String fingerprint) { return fingerprint(privateKey.getPublicExponent(), privateKey.getModulus()).equals(fingerprint); }
/** * @return true if the keypair has the same fingerprint as supplied */ public static boolean publicKeyHasFingerprint(RSAPublicKeySpec publicKey, String fingerprint) { return fingerprint(publicKey.getPublicExponent(), publicKey.getModulus()).equals(fingerprint); }
/** * @param privateKeyPEM * RSA private key in PEM format * @return fingerprint ex. {@code 2b:a9:62:95:5b:8b:1d:61:e0:92:f7:03:10:e9:db:d9} */ public static String fingerprintPrivateKey(String privateKeyPEM) { KeySpec privateKeySpec = privateKeySpec(privateKeyPEM); checkArgument(privateKeySpec instanceof RSAPrivateCrtKeySpec, "incorrect format expected RSAPrivateCrtKeySpec was %s", privateKeySpec); RSAPrivateCrtKeySpec certKeySpec = RSAPrivateCrtKeySpec.class.cast(privateKeySpec); return fingerprint(certKeySpec.getPublicExponent(), certKeySpec.getModulus()); }
/** * @param privateKeyPEM * RSA private key in PEM format * @return fingerprint ex. {@code 2b:a9:62:95:5b:8b:1d:61:e0:92:f7:03:10:e9:db:d9} */ public static String fingerprintPrivateKey(String privateKeyPEM) { KeySpec privateKeySpec = privateKeySpec(privateKeyPEM); checkArgument(privateKeySpec instanceof RSAPrivateCrtKeySpec, "incorrect format expected RSAPrivateCrtKeySpec was %s", privateKeySpec); RSAPrivateCrtKeySpec certKeySpec = RSAPrivateCrtKeySpec.class.cast(privateKeySpec); return fingerprint(certKeySpec.getPublicExponent(), certKeySpec.getModulus()); }
/** * @param privateKeyPEM * RSA private key in PEM format * @return fingerprint ex. {@code 2b:a9:62:95:5b:8b:1d:61:e0:92:f7:03:10:e9:db:d9} */ public static String fingerprintPrivateKey(String privateKeyPEM) { KeySpec privateKeySpec = privateKeySpec(privateKeyPEM); checkArgument(privateKeySpec instanceof RSAPrivateCrtKeySpec, "incorrect format expected RSAPrivateCrtKeySpec was %s", privateKeySpec); RSAPrivateCrtKeySpec certKeySpec = RSAPrivateCrtKeySpec.class.cast(privateKeySpec); return fingerprint(certKeySpec.getPublicExponent(), certKeySpec.getModulus()); }
/** * @param privateKeyPEM * RSA private key in PEM format * @return fingerprint ex. {@code 2b:a9:62:95:5b:8b:1d:61:e0:92:f7:03:10:e9:db:d9} */ public static String fingerprintPrivateKey(String privateKeyPEM) { KeySpec privateKeySpec = privateKeySpec(privateKeyPEM); checkArgument(privateKeySpec instanceof RSAPrivateCrtKeySpec, "incorrect format expected RSAPrivateCrtKeySpec was %s", privateKeySpec); RSAPrivateCrtKeySpec certKeySpec = RSAPrivateCrtKeySpec.class.cast(privateKeySpec); return fingerprint(certKeySpec.getPublicExponent(), certKeySpec.getModulus()); }
/** * @param publicKeyOpenSSH * RSA public key in OpenSSH format * @return fingerprint ex. {@code 2b:a9:62:95:5b:8b:1d:61:e0:92:f7:03:10:e9:db:d9} */ public static String fingerprintPublicKey(String publicKeyOpenSSH) { RSAPublicKeySpec publicKeySpec = publicKeySpecFromOpenSSH(publicKeyOpenSSH); return fingerprint(publicKeySpec.getPublicExponent(), publicKeySpec.getModulus()); }
/** * @param publicKeyOpenSSH * RSA public key in OpenSSH format * @return fingerprint ex. {@code 2b:a9:62:95:5b:8b:1d:61:e0:92:f7:03:10:e9:db:d9} */ public static String fingerprintPublicKey(String publicKeyOpenSSH) { RSAPublicKeySpec publicKeySpec = publicKeySpecFromOpenSSH(publicKeyOpenSSH); return fingerprint(publicKeySpec.getPublicExponent(), publicKeySpec.getModulus()); }
/** * @param publicKeyOpenSSH * RSA public key in OpenSSH format * @return fingerprint ex. {@code 2b:a9:62:95:5b:8b:1d:61:e0:92:f7:03:10:e9:db:d9} */ public static String fingerprintPublicKey(String publicKeyOpenSSH) { RSAPublicKeySpec publicKeySpec = publicKeySpecFromOpenSSH(publicKeyOpenSSH); return fingerprint(publicKeySpec.getPublicExponent(), publicKeySpec.getModulus()); }
/** * @param publicKeyOpenSSH * RSA public key in OpenSSH format * @return fingerprint ex. {@code 2b:a9:62:95:5b:8b:1d:61:e0:92:f7:03:10:e9:db:d9} */ public static String fingerprintPublicKey(String publicKeyOpenSSH) { RSAPublicKeySpec publicKeySpec = publicKeySpecFromOpenSSH(publicKeyOpenSSH); return fingerprint(publicKeySpec.getPublicExponent(), publicKeySpec.getModulus()); }
@Test public void testCanReadRsaAndCompareFingerprintOnPrivateRSAKey() throws IOException { String privKey = Strings2.toStringAndClose(getClass().getResourceAsStream("/test")); RSAPrivateCrtKeySpec key = (RSAPrivateCrtKeySpec) Pems.privateKeySpec(privKey); String fingerPrint = fingerprint(key.getPublicExponent(), key.getModulus()); assertEquals(fingerPrint, expectedFingerprint); }
@Test public void testCanReadRsaAndCompareFingerprintOnPublicRSAKey() throws IOException { String pubKey = Strings2.toStringAndClose(getClass().getResourceAsStream("/test.pub")); RSAPublicKeySpec key = SshKeys.publicKeySpecFromOpenSSH(pubKey); String fingerPrint = fingerprint(key.getPublicExponent(), key.getModulus()); assertEquals(fingerPrint, expectedFingerprint); }
@Test public void testCanReadRsaAndCompareFingerprintOnPublicRSAKey() throws IOException { String pubKey = Strings2.toStringAndClose(getClass().getResourceAsStream("/test.pub")); RSAPublicKeySpec key = SshKeys.publicKeySpecFromOpenSSH(pubKey); String fingerPrint = fingerprint(key.getPublicExponent(), key.getModulus()); assertEquals(fingerPrint, expectedFingerprint); }