1 19 20 package com.sslexplorer.security.pki; 21 22 import java.security.PublicKey ; 23 24 import com.maverick.crypto.digests.Hash; 25 26 27 32 public abstract class SshPublicKey { 33 38 public abstract String getAlgorithmName(); 39 40 45 public abstract int getBitLength(); 46 47 48 public abstract PublicKey getPublicKey(); 49 50 55 public abstract byte[] getEncoded(); 56 57 62 public String getFingerprint() { 63 Hash md5 = new Hash("MD5"); 64 md5.putBytes(getEncoded()); 65 66 byte[] digest = md5.doFinal(); 67 int bits = getBitLength(); 68 bits = (((bits % 8) != 0) ? (bits += (bits % 8)) : bits); 69 70 String ret = String.valueOf(bits); 71 72 for (int i = 0; i < digest.length; i++) { 73 ret += (((i == 0) ? ":" : "") + " " + 74 Integer.toHexString(digest[i] & 0xFF)); 75 } 76 77 return ret; 78 } 79 80 87 public boolean equals(Object obj) { 88 if (obj instanceof SshPublicKey) { 89 return (getFingerprint().compareTo(((SshPublicKey) obj).getFingerprint()) == 0); 90 } 91 92 return false; 93 } 94 95 100 public int hashCode() { 101 return getFingerprint().hashCode(); 102 } 103 104 114 public abstract boolean verifySignature(byte[] signature, 115 byte[] exchangeHash) throws InvalidSignatureException; 116 } 117 | Popular Tags |