Class PuTTYKeyFile
java.lang.Object
net.schmizz.sshj.userauth.keyprovider.BaseFileKeyProvider
net.schmizz.sshj.userauth.keyprovider.PuTTYKeyFile
- All Implemented Interfaces:
FileKeyProvider,KeyProvider
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 -
Field Summary
FieldsModifier and TypeFieldDescriptionFor each line that looks like "Xyz: vvv", it will be stored in this map.private static final Stringprivate Integerprivate byte[]private byte[]private byte[]Fields inherited from class net.schmizz.sshj.userauth.keyprovider.BaseFileKeyProvider
kp, pwdf, resource, type -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate byte[]decrypt(byte[] privateKey, char[] passphrase) Decrypt private keyintgetType()Key typeprivate voidinitCipher(char[] passphrase, Cipher cipher) Initialize Java Cipher for decryption using Secret Key derived from passphrase according to PuTTY Key Versionbooleanprotected voidprivate MacprepareVerifyMacV2(char[] passphrase) private Macprotected KeyPairprivate voidVerify the MAC (only required for v1/v2 keys.
-
Field Details
-
KEY_DERIVATION_HEADER
- See Also:
-
keyFileVersion
-
privateKey
private byte[] privateKey -
publicKey
private byte[] publicKey -
verifyHmac
private byte[] verifyHmac -
payload
-
headers
For each line that looks like "Xyz: vvv", it will be stored in this map.
-
-
Constructor Details
-
PuTTYKeyFile
public PuTTYKeyFile()
-
-
Method Details
-
getType
Key type- Specified by:
getTypein interfaceKeyProvider- Overrides:
getTypein classBaseFileKeyProvider- Returns:
- the
KeyType. - Throws:
IOException- if there is an I/O error retrieving the key type
-
isEncrypted
- Throws:
IOException
-
readKeyPair
- Specified by:
readKeyPairin classBaseFileKeyProvider- Throws:
IOException
-
parseKeyPair
- Throws:
IOException
-
initCipher
private void initCipher(char[] passphrase, Cipher cipher) throws InvalidAlgorithmParameterException, InvalidKeyException Initialize Java Cipher for decryption using Secret Key derived from passphrase according to PuTTY Key Version -
verify
Verify the MAC (only required for v1/v2 keys. v3 keys are automatically verified as part of the decryption process.- Throws:
IOException
-
prepareVerifyMacV2
- Throws:
IOException
-
prepareVerifyMacV3
- Throws:
IOException
-
decrypt
Decrypt private key- Parameters:
privateKey- the SSH private key to be decryptedpassphrase- To decrypt- Throws:
IOException
-
getKeyFileVersion
public int getKeyFileVersion()
-