Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

PrivateKeyFile can't read encrypted keys in Blazor WebAssembly #1870

Open

Description

@pscheid92

Hi, and thanks for SSH.NET!

I'm using PrivateKeyFile in a Blazor WebAssembly app, only to read passphrase-protected keys. (I know SSH connections can't work in the browser, see #1389.)

Keys encrypted with aes-gcm or chacha20-poly1305 open fine. But keys encrypted with aes-ctr, which is ssh-keygen's default, or aes-cbc throw a PlatformNotSupportedException. RSA and ECDSA keys fail the same way, even with aes-gcm, once they're decrypted.

The reason is that .NET in the browser has no Aes, RSA or ECDsa. (Oddly, Aes.Create() still succeeds; it's CreateEncryptor() that throws.)

To reproduce, create a key with ssh-keygen -t ed25519 -N hunter2 -f key and open it with new PrivateKeyFile(stream, "hunter2") in a Blazor WebAssembly app. I used SSH.NET 2026.0.1 and .NET 10.

A possible fix

#1450 solved this for AES-GCM by falling back to BouncyCastle. The same idea works for the rest, in the browser only, so nothing changes on other platforms:

  • AES-CTR/CBC: use BouncyCastle's AesEngine with SSH.NET's existing CBC and CTR modes.
  • RSA: in the browser, create the internal RSA object when it's first needed rather than in the RsaKey constructor. Only signing uses it.
  • ECDSA: use the BouncyCastle implementation EcdsaKey already has for Mono. (It never sets PrivateKey, by the way, so that's null on Mono today.)

I have a working patch, about 160 lines plus tests for the AES part. With it, all of these keys open in the browser and give the same key material as on desktop. If that sounds useful, I'd be happy to open a PR.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions