using System; using System.Security.Cryptography; using Renci.SshNet.Common; using Renci.SshNet.Security.Cryptography.Ciphers; namespace Renci.SshNet.Security.Cryptography { /// /// Implements RSA digital signature algorithm. /// public class RsaDigitalSignature : CipherDigitalSignature, IDisposable { private HashAlgorithm _hash; /// /// Initializes a new instance of the class. /// /// The RSA key. public RsaDigitalSignature(RsaKey rsaKey) : base(new ObjectIdentifier(1, 3, 14, 3, 2, 26), new RsaCipher(rsaKey)) { _hash = HashAlgorithmFactory.CreateSHA1(); } /// /// Hashes the specified input. /// /// The input. /// /// Hashed data. /// protected override byte[] Hash(byte[] input) { return _hash.ComputeHash(input); } #region IDisposable Members private bool _isDisposed; /// /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged ResourceMessages. /// public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } /// /// Releases unmanaged and - optionally - managed resources /// /// true to release both managed and unmanaged resources; false to release only unmanaged ResourceMessages. protected virtual void Dispose(bool disposing) { if (_isDisposed) return; if (disposing) { if (_hash != null) { _hash.Dispose(); _hash = null; } _isDisposed = true; } } /// /// Releases unmanaged resources and performs other cleanup operations before the /// is reclaimed by garbage collection. /// ~RsaDigitalSignature() { // Do not re-create Dispose clean-up code here. // Calling Dispose(false) is optimal in terms of // readability and maintainability. Dispose(false); } #endregion } }