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 Integer
private 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[]
Uses BouncyCastle Argon2 implementationprivate byte[]
decrypt
(byte[] privateKey, char[] passphrase) Decrypt private keyint
getType()
Key typeprivate void
initCipher
(char[] passphrase, Cipher cipher) Converts a passphrase into a key, by following the convention that PuTTY uses.boolean
protected void
private Mac
prepareVerifyMacV2
(char[] passphrase) private Mac
protected KeyPair
private void
Verify the MAC (only required for v1/v2 keys.
-
Field Details
-
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:
getType
in interfaceKeyProvider
- Overrides:
getType
in classBaseFileKeyProvider
- Returns:
- the
KeyType
. - Throws:
IOException
- if there is an I/O error retrieving the key type
-
isEncrypted
- Throws:
IOException
-
readKeyPair
- Specified by:
readKeyPair
in classBaseFileKeyProvider
- Throws:
IOException
-
parseKeyPair
- Throws:
IOException
-
initCipher
private void initCipher(char[] passphrase, Cipher cipher) throws IOException, InvalidAlgorithmParameterException, InvalidKeyException Converts a passphrase into a key, by following the convention that PuTTY uses. Only PuTTY v1/v2 key files This is used to decrypt the private key when it's encrypted. -
argon2
Uses BouncyCastle Argon2 implementation- Throws:
IOException
-
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()
-