<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.Runtime.CompilerServices; 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) { DefaultInterpolatedStringHandler defaultInterpolatedStringHandler = new DefaultInterpolatedStringHandler(26, 2); defaultInterpolatedStringHandler.AppendLiteral("Could not create "); defaultInterpolatedStringHandler.AppendFormatted("HashAlgorithm"); defaultInterpolatedStringHandler.AppendLiteral(" from `"); defaultInterpolatedStringHandler.AppendFormatted(hashAlgorithmName); defaultInterpolatedStringHandler.AppendLiteral("`."); throw new ArgumentException(defaultInterpolatedStringHandler.ToStringAndClear(), "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); } } }