Example #1
0
        /// <summary>Displays an X.509 certificate in text format.</summary>
        /// <returns>The certificate information.</returns>
        /// <param name="verbose">true to display the public key, private key, extensions, and so forth; false to display information that is similar to the <see cref="T:System.Security.Cryptography.X509Certificates.X509Certificate2" /> class, including thumbprint, serial number, subject and issuer names, and so on. </param>
        public override string ToString(bool verbose)
        {
            if (this._cert == null)
            {
                return("System.Security.Cryptography.X509Certificates.X509Certificate2");
            }
            if (!verbose)
            {
                return(base.ToString(true));
            }
            string        newLine       = Environment.NewLine;
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.AppendFormat("[Version]{0}  V{1}{0}{0}", newLine, this.Version);
            stringBuilder.AppendFormat("[Subject]{0}  {1}{0}{0}", newLine, base.Subject);
            stringBuilder.AppendFormat("[Issuer]{0}  {1}{0}{0}", newLine, base.Issuer);
            stringBuilder.AppendFormat("[Serial Number]{0}  {1}{0}{0}", newLine, this.SerialNumber);
            stringBuilder.AppendFormat("[Not Before]{0}  {1}{0}{0}", newLine, this.NotBefore);
            stringBuilder.AppendFormat("[Not After]{0}  {1}{0}{0}", newLine, this.NotAfter);
            stringBuilder.AppendFormat("[Thumbprint]{0}  {1}{0}{0}", newLine, this.Thumbprint);
            stringBuilder.AppendFormat("[Signature Algorithm]{0}  {1}({2}){0}{0}", newLine, this.SignatureAlgorithm.FriendlyName, this.SignatureAlgorithm.Value);
            AsymmetricAlgorithm key = this.PublicKey.Key;

            stringBuilder.AppendFormat("[Public Key]{0}  Algorithm: ", newLine);
            if (key is RSA)
            {
                stringBuilder.Append("RSA");
            }
            else if (key is DSA)
            {
                stringBuilder.Append("DSA");
            }
            else
            {
                stringBuilder.Append(key.ToString());
            }
            stringBuilder.AppendFormat("{0}  Length: {1}{0}  Key Blob: ", newLine, key.KeySize);
            X509Certificate2.AppendBuffer(stringBuilder, this.PublicKey.EncodedKeyValue.RawData);
            stringBuilder.AppendFormat("{0}  Parameters: ", newLine);
            X509Certificate2.AppendBuffer(stringBuilder, this.PublicKey.EncodedParameters.RawData);
            stringBuilder.Append(newLine);
            return(stringBuilder.ToString());
        }