Class KeyPair

java.lang.Object
com.jcraft.jsch.KeyPair
Direct Known Subclasses:
KeyPairDSA, KeyPairECDSA, KeyPairPKCS8, KeyPairRSA

public abstract class KeyPair extends Object
  • Field Details

    • ERROR

      public static final int ERROR
      See Also:
    • DSA

      public static final int DSA
      See Also:
    • RSA

      public static final int RSA
      See Also:
    • ECDSA

      public static final int ECDSA
      See Also:
    • UNKNOWN

      public static final int UNKNOWN
      See Also:
    • VENDOR_OPENSSH

      static final int VENDOR_OPENSSH
      See Also:
    • VENDOR_FSECURE

      static final int VENDOR_FSECURE
      See Also:
    • VENDOR_PUTTY

      static final int VENDOR_PUTTY
      See Also:
    • VENDOR_PKCS8

      static final int VENDOR_PKCS8
      See Also:
    • vendor

      int vendor
    • cr

      private static final byte[] cr
    • publicKeyComment

      protected String publicKeyComment
    • jsch

      JSch jsch
    • cipher

      private Cipher cipher
    • hash

      private HASH hash
    • random

      private Random random
    • passphrase

      private byte[] passphrase
    • space

      private static byte[] space
    • encrypted

      protected boolean encrypted
    • data

      protected byte[] data
    • iv

      private byte[] iv
    • publickeyblob

      private byte[] publickeyblob
    • header1

      private static final String[] header1
    • header2

      private static final String[] header2
    • header3

      private static final String[] header3
  • Constructor Details

    • KeyPair

      public KeyPair(JSch jsch)
  • Method Details

    • genKeyPair

      public static KeyPair genKeyPair(JSch jsch, int type) throws JSchException
      Throws:
      JSchException
    • genKeyPair

      public static KeyPair genKeyPair(JSch jsch, int type, int key_size) throws JSchException
      Throws:
      JSchException
    • generate

      abstract void generate(int key_size) throws JSchException
      Throws:
      JSchException
    • getBegin

      abstract byte[] getBegin()
    • getEnd

      abstract byte[] getEnd()
    • getKeySize

      abstract int getKeySize()
    • getSignature

      public abstract byte[] getSignature(byte[] data)
    • getVerifier

      public abstract Signature getVerifier()
    • forSSHAgent

      public abstract byte[] forSSHAgent() throws JSchException
      Throws:
      JSchException
    • getPublicKeyComment

      public String getPublicKeyComment()
    • setPublicKeyComment

      public void setPublicKeyComment(String publicKeyComment)
    • getPrivateKey

      abstract byte[] getPrivateKey()
    • writePrivateKey

      public void writePrivateKey(OutputStream out)
      Writes the plain private key to the given output stream.
      Parameters:
      out - output stream
      See Also:
    • writePrivateKey

      public void writePrivateKey(OutputStream out, byte[] passphrase)
      Writes the cyphered private key to the given output stream.
      Parameters:
      out - output stream
      passphrase - a passphrase to encrypt the private key
    • getKeyTypeName

      abstract byte[] getKeyTypeName()
    • getKeyType

      public abstract int getKeyType()
    • getPublicKeyBlob

      public byte[] getPublicKeyBlob()
      Returns the blob of the public key.
      Returns:
      blob of the public key
    • writePublicKey

      public void writePublicKey(OutputStream out, String comment)
      Writes the public key with the specified comment to the output stream.
      Parameters:
      out - output stream
      comment - comment
    • writePublicKey

      public void writePublicKey(String name, String comment) throws FileNotFoundException, IOException
      Writes the public key with the specified comment to the file.
      Parameters:
      name - file name
      comment - comment
      Throws:
      FileNotFoundException
      IOException
      See Also:
    • writeSECSHPublicKey

      public void writeSECSHPublicKey(OutputStream out, String comment)
      Writes the public key with the specified comment to the output stream in the format defined in http://www.ietf.org/rfc/rfc4716.txt
      Parameters:
      out - output stream
      comment - comment
    • writeSECSHPublicKey

      public void writeSECSHPublicKey(String name, String comment) throws FileNotFoundException, IOException
      Writes the public key with the specified comment to the output stream in the format defined in http://www.ietf.org/rfc/rfc4716.txt
      Parameters:
      name - file name
      comment - comment
      Throws:
      FileNotFoundException
      IOException
      See Also:
    • writePrivateKey

      public void writePrivateKey(String name) throws FileNotFoundException, IOException
      Writes the plain private key to the file.
      Parameters:
      name - file name
      Throws:
      FileNotFoundException
      IOException
      See Also:
    • writePrivateKey

      public void writePrivateKey(String name, byte[] passphrase) throws FileNotFoundException, IOException
      Writes the cyphered private key to the file.
      Parameters:
      name - file name
      passphrase - a passphrase to encrypt the private key
      Throws:
      FileNotFoundException
      IOException
      See Also:
    • getFingerPrint

      public String getFingerPrint()
      Returns the finger-print of the public key.
      Returns:
      finger print
    • encrypt

      private byte[] encrypt(byte[] plain, byte[][] _iv, byte[] passphrase)
    • parse

      abstract boolean parse(byte[] data)
    • decrypt

      private byte[] decrypt(byte[] data, byte[] passphrase, byte[] iv)
    • writeSEQUENCE

      int writeSEQUENCE(byte[] buf, int index, int len)
    • writeINTEGER

      int writeINTEGER(byte[] buf, int index, byte[] data)
    • writeOCTETSTRING

      int writeOCTETSTRING(byte[] buf, int index, byte[] data)
    • writeDATA

      int writeDATA(byte[] buf, byte n, int index, byte[] data)
    • countLength

      int countLength(int len)
    • writeLength

      int writeLength(byte[] data, int index, int len)
    • genRandom

      private Random genRandom()
    • genHash

      private HASH genHash()
    • genCipher

      private Cipher genCipher()
    • genKey

      byte[] genKey(byte[] passphrase, byte[] iv)
    • setPassphrase

      public void setPassphrase(String passphrase)
      Deprecated.
      use #writePrivateKey(java.io.OutputStream out, byte[] passphrase)
    • setPassphrase

      public void setPassphrase(byte[] passphrase)
      Deprecated.
      use #writePrivateKey(String name, byte[] passphrase)
    • isEncrypted

      public boolean isEncrypted()
    • decrypt

      public boolean decrypt(String _passphrase)
    • decrypt

      public boolean decrypt(byte[] _passphrase)
    • load

      public static KeyPair load(JSch jsch, String prvkey) throws JSchException
      Throws:
      JSchException
    • load

      public static KeyPair load(JSch jsch, String prvfile, String pubfile) throws JSchException
      Throws:
      JSchException
    • load

      public static KeyPair load(JSch jsch, byte[] prvkey, byte[] pubkey) throws JSchException
      Throws:
      JSchException
    • a2b

      private static byte a2b(byte c)
    • b2a

      private static byte b2a(byte c)
    • dispose

      public void dispose()
    • finalize

      public void finalize()
      Overrides:
      finalize in class Object
    • loadPPK

      static KeyPair loadPPK(JSch jsch, byte[] buf) throws JSchException
      Throws:
      JSchException
    • parseLines

      private static byte[] parseLines(Buffer buffer, int lines)
    • parseHeader

      private static boolean parseHeader(Buffer buffer, Hashtable v)
    • copy

      void copy(KeyPair kpair)