Package hudson.plugins.ec2.util
Class KeyHelper
java.lang.Object
hudson.plugins.ec2.util.KeyHelper
Utility class to parse PEM.
-
Method Summary
Modifier and TypeMethodDescriptionstatic KeyPairdecodeKeyPair(String pem, String password) Decodes a PEM-encoded key pair into aKeyPairobject.static StringgetFingerprint(PublicKey serverKey) Computes the MD5 fingerprint of the given server public key.static StringgetSshAlgorithm(PublicKey serverKey) Determines the SSH algorithm identifier corresponding to the given server public key.
-
Method Details
-
decodeKeyPair
public static KeyPair decodeKeyPair(@NonNull String pem, @NonNull String password) throws IOException Decodes a PEM-encoded key pair into aKeyPairobject. This method supports various types of PEM input such as encrypted private keys, public keys, and key pairs.- Parameters:
pem- The PEM-formatted string containing the key data.password- The password used to decrypt encrypted key pairs, if applicable. Can be null if no password is required.- Returns:
- A
KeyPaircontaining the public and private keys. If a public key is provided without a matching private key, the private key in the returnedKeyPairwill be null. - Throws:
IOException- If an error occurs during parsing or decryption of the PEM input.IllegalArgumentException- If the provided PEM input cannot be parsed or is of an unsupported type.
-
getSshAlgorithm
Determines the SSH algorithm identifier corresponding to the given server public key. This method matches the key type to the appropriate SSH algorithm string. When anECPublicKeyis given, an NIST curse will be assumed.- Parameters:
serverKey- The server'sPublicKeyobject for which the SSH algorithm identifier needs to be determined.- Returns:
- A
Stringrepresenting the SSH algorithm identifier for the given server key, ornullif the key type is unsupported or cannot be determined.
-
getFingerprint
Computes the MD5 fingerprint of the given server public key. The fingerprint is formatted as a colon-separated hexadecimal string.- Parameters:
serverKey- The server'sPublicKeyobject for which the fingerprint needs to be computed.- Returns:
- A
Stringrepresenting the MD5 fingerprint of the given server key in colon-separated hexadecimal format, or an empty string if an error occurs during computation.
-