use of org.apache.sshd.common.SshException in project gerrit by GerritCodeReview.
the class SshUtil method parse.
/**
* Parse a public key into its Java type.
*
* @param key the account key to parse.
* @return the valid public key object.
* @throws InvalidKeySpecException the key supplied is not a valid SSH key.
* @throws NoSuchAlgorithmException the JVM is missing the key algorithm.
* @throws NoSuchProviderException the JVM is missing the provider.
*/
public static PublicKey parse(AccountSshKey key) throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchProviderException {
try {
final String s = key.encodedKey();
if (s == null) {
throw new InvalidKeySpecException("No key string");
}
final byte[] bin = BaseEncoding.base64().decode(s);
return new ByteArrayBuffer(bin).getRawPublicKey();
} catch (RuntimeException | SshException e) {
throw new InvalidKeySpecException("Cannot parse key", e);
}
}
Aggregations