| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181 | using System;using System.Collections.Generic;using System.Linq;using System.Text;using Renci.SshNet.Common;using Renci.SshNet.Security.Cryptography;namespace Renci.SshNet.Security{    /// <summary>    /// Contains DSA private and public key    /// </summary>    public class DsaKey : Key, IDisposable    {        /// <summary>        /// Gets the P.        /// </summary>        public BigInteger P        {            get            {                return this._privateKey[0];            }        }        /// <summary>        /// Gets the Q.        /// </summary>        public BigInteger Q        {            get            {                return this._privateKey[1];            }        }        /// <summary>        /// Gets the G.        /// </summary>        public BigInteger G        {            get            {                return this._privateKey[2];            }        }        /// <summary>        /// Gets public key Y.        /// </summary>        public BigInteger Y        {            get            {                return this._privateKey[3];            }        }        /// <summary>        /// Gets private key X.        /// </summary>        public BigInteger X        {            get            {                return this._privateKey[4];            }        }        private DsaDigitalSignature _digitalSignature;        /// <summary>        /// Gets the digital signature.        /// </summary>        protected override DigitalSignature DigitalSignature        {            get            {                if (this._digitalSignature == null)                {                    this._digitalSignature = new DsaDigitalSignature(this);                }                return this._digitalSignature;            }        }        /// <summary>        /// Gets or sets the public.        /// </summary>        /// <value>        /// The public.        /// </value>        public override BigInteger[] Public        {            get            {                return new BigInteger[] { this.P, this.Q, this.G, this.Y };            }            set            {                if (value.Length != 4)                    throw new InvalidOperationException("Invalid public key.");                                this._privateKey = value;            }        }        /// <summary>        /// Initializes a new instance of the <see cref="DsaKey"/> class.        /// </summary>        public DsaKey()            : base()        {            this._privateKey = new BigInteger[5];        }        /// <summary>        /// Initializes a new instance of the <see cref="DsaKey"/> class.        /// </summary>        /// <param name="data">DER encoded private key data.</param>        public DsaKey(byte[] data)            : base(data)        {            if (this._privateKey.Length != 5)                throw new InvalidOperationException("Invalid private key.");        }                    #region IDisposable Members        private bool _isDisposed = false;        /// <summary>        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged ResourceMessages.        /// </summary>        public void Dispose()        {            Dispose(true);            GC.SuppressFinalize(this);        }        /// <summary>        /// Releases unmanaged and - optionally - managed resources        /// </summary>        /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged ResourceMessages.</param>        protected virtual void Dispose(bool disposing)        {            // Check to see if Dispose has already been called.            if (!this._isDisposed)            {                // If disposing equals true, dispose all managed                // and unmanaged ResourceMessages.                if (disposing)                {                    // Dispose managed ResourceMessages.                    if (this._digitalSignature != null)                    {                        this._digitalSignature.Dispose();                        this._digitalSignature = null;                    }                }                // Note disposing has been done.                this._isDisposed = true;            }        }        /// <summary>        /// Releases unmanaged resources and performs other cleanup operations before the        /// <see cref="SshCommand"/> is reclaimed by garbage collection.        /// </summary>        ~DsaKey()        {            // Do not re-create Dispose clean-up code here.            // Calling Dispose(false) is optimal in terms of            // readability and maintainability.            Dispose(false);        }        #endregion    }}
 |