Method SaveAsync
- Namespace
- SshSharp
- Assembly
- SshSharp.dll
SaveAsync(string, string?, CancellationToken)
Writes the key as ssh-keygen does: the private key to path (ToOpenSshPrivateKey(string?, int)), readable
only by the current user (mode 0600 on Unix, an owner-only ACL on Windows), and the public key to path.pub.
Neither file may exist yet: an existing key is never overwritten.
public Task SaveAsync(string path, string? passphrase = null, CancellationToken cancellationToken = default)
Parameters
pathstringThe private key file, for example
~/.ssh/id_ed25519.passphrasestringThe passphrase to encrypt with; null or empty for an unencrypted key.
cancellationTokenCancellationTokenCancels writing.
Returns
Exceptions
- IOException
One of the files exists already, or could not be written.
- NotSupportedException
The private key is not available: a key held by an agent or an external signer, or one paired with a certificate (export the key it was made from).
SaveAsync(string, string?, int, CancellationToken)
Writes the key as SaveAsync(string, string?, CancellationToken) does, encrypted with kdfRounds
rounds of bcrypt_pbkdf (ssh-keygen -a).
public Task SaveAsync(string path, string? passphrase, int kdfRounds, CancellationToken cancellationToken = default)
Parameters
pathstringThe private key file, for example
~/.ssh/id_ed25519.passphrasestringThe passphrase to encrypt with; null or empty for an unencrypted key.
kdfRoundsintbcrypt_pbkdf rounds: 16 is ssh-keygen's default; more make guessing the passphrase slower, and loading the key too. From 1 to 65536.
cancellationTokenCancellationTokenCancels writing.
Returns
Exceptions
- ArgumentOutOfRangeException
kdfRoundsis out of range.- IOException
One of the files exists already, or could not be written.
- NotSupportedException
The private key is not available: a key held by an agent or an external signer, or one paired with a certificate (export the key it was made from).
SaveAsync(string, SshPrivateKeyFormat, string?, CancellationToken)
Writes the key in format: the private key to path (ToOpenSshPrivateKey(string?, int),
ToPkcs8PrivateKey(string?) or ToPuttyPrivateKey(string?)), readable only by the current user (mode 0600 on Unix, an
owner-only ACL on Windows), and the public key to path.pub as an authorized_keys line, for every
format. Neither file may exist yet: an existing key is never overwritten.
public Task SaveAsync(string path, SshPrivateKeyFormat format, string? passphrase = null, CancellationToken cancellationToken = default)
Parameters
pathstringThe private key file, for example
~/.ssh/id_ed25519, orid_ed25519.ppkfor PuTTY.formatSshPrivateKeyFormatThe file format.
passphrasestringThe passphrase to encrypt with; null or empty for an unencrypted key.
cancellationTokenCancellationTokenCancels writing.
Returns
Exceptions
- ArgumentOutOfRangeException
formatis not a defined format.- IOException
One of the files exists already, or could not be written.
- NotSupportedException
The private key is not available (a key held by an agent or an external signer, or one paired with a certificate), or the format cannot hold this key: see ToPkcs8PrivateKey(string?) and ToPuttyPrivateKey(string?).