Class SshPublicKeyFileFactory

java.lang.Object
com.sshtools.common.publickey.SshPublicKeyFileFactory

public class SshPublicKeyFileFactory extends Object
Public key format factory used to decode different formats of public keys. The following types of public keys are currently supported:
 OpenSSH
 
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAQQC8OZmB4d+SSMtVgsvdsCqRovgwcL/SYZunIBlR mCO6LhY/8PqefhygKfIZcxyGCKcrVAO4THGbqZ/ilv8NWXJT This is a comment
SECSH standard format
---- BEGIN SSH2 PUBLIC KEY ---- Comment: "This is a comment" AAAAB3NzaC1yc2EAAAADAQABAAAAgQC9mPcvyCnWpuvN7u4cjwUkBbTqgYm5kR92XNbo7/ElAJY+ 7HwoTtiUsQ6Q2Ma6hUg29LlDifpX5Ujwwm5PRK+7dXWL5bbznNGxJXY5P1E/5cr/+cJueaqZuA90 2x6oFweQZPK4en+nJyXFwYY/Pbf86F3EJFD3lh9RWSN7r2RbRw== ---- END SSH2 PUBLIC KEY ----
SSH1
1024 65537 12203618663441486180278392644721081332612879088348276482061792 3981996764870633915934678786242627941442492506374351346273236223683187153 1433842142721049328324552410746419300820752745317401639942167156433029893 3759921689255688343334770869709776055449427739142029076904194522024626419 9127925140284440450097198129
Author:
Lee David Painter
  • Field Details

  • Constructor Details

    • SshPublicKeyFileFactory

      public SshPublicKeyFileFactory()
  • Method Details

    • decodeSSH2PublicKey

      public static SshPublicKey decodeSSH2PublicKey(byte[] encoded) throws IOException
      Decode an SSH2 encoded public key as specified in the SSH2 transport protocol. This consists of a String identifier specifying the algorithm of the public key and the remaining data is formatted depending upon the public key type. The supported key types are as follows:
       ssh-rsa is encoded as
       String        "ssh-rsa"
       BigInteger    e
       BigInteger    n
       
       ssh-dsa is encoded as
       String        "ssh-dsa"
       BigInteger    p
       BigInteger    q
       BigItneger    g
       BigInteger    y
       
      Parameters:
      encoded -
      Returns:
      SshPublicKey
      Throws:
      IOException
    • decodeSSH2PublicKey

      public static SshPublicKey decodeSSH2PublicKey(String algorithm, byte[] encoded) throws IOException
      Throws:
      IOException
    • parse

      public static SshPublicKeyFile parse(byte[] formattedkey) throws IOException
      Parse a formatted public key and return a file representation.
      Parameters:
      formattedkey -
      Returns:
      SshPublicKeyFile
      Throws:
      IOException
    • parse

      public static SshPublicKeyFile parse(InputStream in) throws IOException
      Parse a formatted key from an InputStream and return a file representation.
      Parameters:
      in -
      Returns:
      SshPublicKeyFile
      Throws:
      IOException
    • create

      public static SshPublicKeyFile create(SshPublicKey key, String comment, int format) throws IOException
      Create a file representation from an existing public key. To generate new keys see <a href="SshKeyPairGenerator.html>SshKeyPairGenerator.
      Parameters:
      key - the public key
      comment - the comment to apply to the formatted key
      format - the format type
      Returns:
      SshPublicKeyFile
      Throws:
      IOException
    • create

      public static SshPublicKeyFile create(SshPublicKey key, String options, String comment, int format) throws IOException
      Create a file representation from an existing public key. To generate new keys see <a href="SshKeyPairGenerator.html>SshKeyPairGenerator.
      Parameters:
      key - the public key
      options - options (if supported)
      comment - the comment to apply to the formatted key
      format - the format type
      Returns:
      SshPublicKeyFile
      Throws:
      IOException
    • createFile

      public static void createFile(SshPublicKey key, String comment, int format, File toFile) throws IOException
      Take a SshPublicKey and write it to a file
      Parameters:
      key -
      comment -
      format -
      toFile -
      Throws:
      IOException
    • convertFile

      public static void convertFile(File keyFile, int toFormat, File toFile) throws IOException
      Take a file in any of the supported public key formats and convert to the requested format.
      Parameters:
      keyFile -
      toFormat -
      toFile -
      Throws:
      IOException