Back to product page

LoadKey method


Loads private key from the file.

Type

None

Syntax

  • Basic
object.LoadKey Filename, [Password]
The LoadKey(object,Filename,Password) syntax has these parts:
objectAn expression evaluating to an object of type Certificate.
FilenameRequired. A String value. Full path to key file on local computer.
PasswordOptional. A Variant value. Password to open saved key.

Remarks

LoadKey method will try to load in memory previously saved key using SaveKey method, or saved using external programs such as ssh-keygen included in OpenSSH package. File should be accessible and readable by yourself in the time when LoadKey is requested.

If LoadKey is successful, Certificate object will recognize key type (RSAkey or DSAkey) and overwrite old one from memory (if any). If you have already loaded valid certificate, and it does not match Key you just tried to load, load will fail.

Saved key should be in PEM format. PEM format is simply base64 encoded data surrounded by header lines (this is the format that is used in Save method) and is widely supported by different SSH implementations. Load additionally transparently handle PKCS#8 format encrypted and unencrypted keys too. Typical structure looks like this (for RSAKey):

-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: DES-EDE3-CFB,33E78EDBC3F91072

bKxPNDjHoqW4wT46OnYnDWtJnhwhqRIh81o9IAjjrrlRRDQf9kefDFuciKBrJCqK
................................................................
                          (...more...)
................................................................
ViWBhtNOV1Wzm3Ifv9ekm6cd1TjPO2UP/Vi5/Xz4PQ+maA7c1QXbdXGF29fc2VFI
JQKZxKKEfirZntyOH6chDQGeYnB7mXLpRNnNb7g=
-----END RSA PRIVATE KEY-----


If loading fails, an error will be generating describing the error. Most common error when loading the key will occur if password does not match one that was used when key was saved.

Besides opening PEM format, LoadKey method will try to open Putty, Vandyke, SSH1.0, SSH.COM and F-Secure generated keys. Also, it will try to open PFX files (PKCS#12 format) and try to find any private keys in that file. When saved, these keys will be saved in PEM format. You may need to remove passphrase from foreign keys when you try to import them with Load method.

Platforms

Windows