<PackageReference Include="SSH.NET" Version="2023.0.1" />

RsaDigitalSignature

Implements RSA digital signature algorithm.
using Renci.SshNet.Common; using Renci.SshNet.Security.Cryptography.Ciphers; using System; using System.Security.Cryptography; namespace Renci.SshNet.Security.Cryptography { public class RsaDigitalSignature : CipherDigitalSignature, IDisposable { private HashAlgorithm _hash; private bool _isDisposed; public RsaDigitalSignature(RsaKey rsaKey) : this(rsaKey, HashAlgorithmName.SHA1) { } public RsaDigitalSignature(RsaKey rsaKey, HashAlgorithmName hashAlgorithmName) : base(ObjectIdentifier.FromHashAlgorithmName(hashAlgorithmName), new RsaCipher(rsaKey)) { HashAlgorithm obj = CryptoConfig.CreateFromName(hashAlgorithmName.Name) as HashAlgorithm; if (obj == null) throw new ArgumentException(string.Format("Could not create {0} from `{1}`.", "HashAlgorithm", hashAlgorithmName), "hashAlgorithmName"); _hash = obj; } protected override byte[] Hash(byte[] input) { return _hash.ComputeHash(input); } public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } protected virtual void Dispose(bool disposing) { if (!_isDisposed && disposing) { HashAlgorithm hash = _hash; if (hash != null) { hash.Dispose(); _hash = null; } _isDisposed = true; } } ~RsaDigitalSignature() { Dispose(false); } } }