Class PuTTYKeyFile
- java.lang.Object
-
- net.schmizz.sshj.userauth.keyprovider.BaseFileKeyProvider
-
- net.schmizz.sshj.userauth.keyprovider.PuTTYKeyFile
-
- All Implemented Interfaces:
FileKeyProvider,KeyProvider
public class PuTTYKeyFile extends BaseFileKeyProvider
Sample PuTTY file format
PuTTY-User-Key-File-2: ssh-rsa Encryption: none Comment: rsa-key-20080514 Public-Lines: 4 AAAAB3NzaC1yc2EAAAABJQAAAIEAiPVUpONjGeVrwgRPOqy3Ym6kF/f8bltnmjA2 BMdAtaOpiD8A2ooqtLS5zWYuc0xkW0ogoKvORN+RF4JI+uNUlkxWxnzJM9JLpnvA HrMoVFaQ0cgDMIHtE1Ob1cGAhlNInPCRnGNJpBNcJ/OJye3yt7WqHP4SPCCLb6nL nmBUrLM= Private-Lines: 8 AAAAgGtYgJzpktzyFjBIkSAmgeVdozVhgKmF6WsDMUID9HKwtU8cn83h6h7ug8qA hUWcvVxO201/vViTjWVz9ALph3uMnpJiuQaaNYIGztGJBRsBwmQW9738pUXcsUXZ 79KJP01oHn6Wkrgk26DIOsz04QOBI6C8RumBO4+F1WdfueM9AAAAQQDmA4hcK8Bx nVtEpcF310mKD3nsbJqARdw5NV9kCxPnEsmy7Sy1L4Ob/nTIrynbc3MA9HQVJkUz 7V0va5Pjm/T7AAAAQQCYbnG0UEekwk0LG1Hkxh1OrKMxCw2KWMN8ac3L0LVBg/Tk 8EnB2oT45GGeJaw7KzdoOMFZz0iXLsVLNUjNn2mpAAAAQQCN6SEfWqiNzyc/w5n/ lFVDHExfVUJp0wXv+kzZzylnw4fs00lC3k4PZDSsb+jYCMesnfJjhDgkUA0XPyo8 Emdk Private-MAC: 50c45751d18d74c00fca395deb7b7695e3ed6f77
- Version:
- $Id:$
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classPuTTYKeyFile.Factory
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.String,java.lang.String>headersFor each line that looks like "Xyz: vvv", it will be stored in this map.private static java.lang.StringKEY_DERIVATION_HEADERprivate java.lang.IntegerkeyFileVersionprivate java.util.Map<java.lang.String,java.lang.String>payloadprivate byte[]privateKeyprivate byte[]publicKeyprivate byte[]verifyHmac-
Fields inherited from class net.schmizz.sshj.userauth.keyprovider.BaseFileKeyProvider
kp, pwdf, resource, type
-
-
Constructor Summary
Constructors Constructor Description PuTTYKeyFile()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private byte[]decrypt(byte[] privateKey, char[] passphrase)Decrypt private keyintgetKeyFileVersion()KeyTypegetType()Key typeprivate voidinitCipher(char[] passphrase, javax.crypto.Cipher cipher)Initialize Java Cipher for decryption using Secret Key derived from passphrase according to PuTTY Key VersionbooleanisEncrypted()protected voidparseKeyPair()private javax.crypto.MacprepareVerifyMacV2(char[] passphrase)private javax.crypto.MacprepareVerifyMacV3()protected java.security.KeyPairreadKeyPair()private voidverify(javax.crypto.Mac mac)Verify the MAC (only required for v1/v2 keys.
-
-
-
Field Detail
-
KEY_DERIVATION_HEADER
private static final java.lang.String KEY_DERIVATION_HEADER
- See Also:
- Constant Field Values
-
keyFileVersion
private java.lang.Integer keyFileVersion
-
privateKey
private byte[] privateKey
-
publicKey
private byte[] publicKey
-
verifyHmac
private byte[] verifyHmac
-
payload
private final java.util.Map<java.lang.String,java.lang.String> payload
-
headers
private final java.util.Map<java.lang.String,java.lang.String> headers
For each line that looks like "Xyz: vvv", it will be stored in this map.
-
-
Method Detail
-
getType
public KeyType getType() throws java.io.IOException
Key type- Specified by:
getTypein interfaceKeyProvider- Overrides:
getTypein classBaseFileKeyProvider- Returns:
- the
KeyType. - Throws:
java.io.IOException- if there is an I/O error retrieving the key type
-
isEncrypted
public boolean isEncrypted() throws java.io.IOException- Throws:
java.io.IOException
-
readKeyPair
protected java.security.KeyPair readKeyPair() throws java.io.IOException- Specified by:
readKeyPairin classBaseFileKeyProvider- Throws:
java.io.IOException
-
parseKeyPair
protected void parseKeyPair() throws java.io.IOException- Throws:
java.io.IOException
-
initCipher
private void initCipher(char[] passphrase, javax.crypto.Cipher cipher) throws java.security.InvalidAlgorithmParameterException, java.security.InvalidKeyExceptionInitialize Java Cipher for decryption using Secret Key derived from passphrase according to PuTTY Key Version- Throws:
java.security.InvalidAlgorithmParameterExceptionjava.security.InvalidKeyException
-
verify
private void verify(javax.crypto.Mac mac) throws java.io.IOExceptionVerify the MAC (only required for v1/v2 keys. v3 keys are automatically verified as part of the decryption process.- Throws:
java.io.IOException
-
prepareVerifyMacV2
private javax.crypto.Mac prepareVerifyMacV2(char[] passphrase) throws java.io.IOException- Throws:
java.io.IOException
-
prepareVerifyMacV3
private javax.crypto.Mac prepareVerifyMacV3() throws java.io.IOException- Throws:
java.io.IOException
-
decrypt
private byte[] decrypt(byte[] privateKey, char[] passphrase) throws java.io.IOExceptionDecrypt private key- Parameters:
privateKey- the SSH private key to be decryptedpassphrase- To decrypt- Throws:
java.io.IOException
-
getKeyFileVersion
public int getKeyFileVersion()
-
-