Method ToPkcs8PrivateKey
- Namespace
- SshSharp
- Assembly
- SshSharp.dll
ToPkcs8PrivateKey(string?)
The key in PKCS#8 PEM, which OpenSSL, ssh-keygen and the .NET cryptography APIs (ImportFromPem(ReadOnlySpan<char>),
ImportFromEncryptedPem(ReadOnlySpan<char>, ReadOnlySpan<char>)) read: BEGIN PRIVATE KEY,
or, when passphrase is given, BEGIN ENCRYPTED PRIVATE KEY, encrypted with AES-256-CBC under a key from
PBKDF2-HMAC-SHA256 with 600,000 iterations (PBES2, RFC 8018). PKCS#8 has no comment: Comment is not kept. The text
holds the private key: do not log it, and write it only to files other users cannot read
(SaveAsync(string, SshPrivateKeyFormat, string?, CancellationToken) does).
public string ToPkcs8PrivateKey(string? passphrase = null)
Parameters
passphrasestringThe passphrase to encrypt with; null or empty for an unencrypted key.
Returns
Exceptions
- 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). Or an Ed25519 key with a passphrase: .NET has no Ed25519, so it cannot encrypt one; use ToOpenSshPrivateKey(string?, int) or ToPuttyPrivateKey(string?) for an encrypted Ed25519 key.