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 class
PuTTYKeyFile.Factory
-
Field Summary
Fields Modifier and Type Field Description private 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.private static java.lang.String
KEY_DERIVATION_HEADER
private java.lang.Integer
keyFileVersion
private java.util.Map<java.lang.String,java.lang.String>
payload
private byte[]
privateKey
private byte[]
publicKey
private 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 keyint
getKeyFileVersion()
KeyType
getType()
Key typeprivate void
initCipher(char[] passphrase, javax.crypto.Cipher cipher)
Initialize Java Cipher for decryption using Secret Key derived from passphrase according to PuTTY Key Versionboolean
isEncrypted()
protected void
parseKeyPair()
private javax.crypto.Mac
prepareVerifyMacV2(char[] passphrase)
private javax.crypto.Mac
prepareVerifyMacV3()
protected java.security.KeyPair
readKeyPair()
private void
verify(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:
getType
in interfaceKeyProvider
- Overrides:
getType
in 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:
readKeyPair
in 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.InvalidKeyException
Initialize Java Cipher for decryption using Secret Key derived from passphrase according to PuTTY Key Version- Throws:
java.security.InvalidAlgorithmParameterException
java.security.InvalidKeyException
-
verify
private void verify(javax.crypto.Mac mac) throws java.io.IOException
Verify 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.IOException
Decrypt private key- Parameters:
privateKey
- the SSH private key to be decryptedpassphrase
- To decrypt- Throws:
java.io.IOException
-
getKeyFileVersion
public int getKeyFileVersion()
-
-