X509RawDataKeyIdentifierClause.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / IdentityModel / System / IdentityModel / Tokens / X509RawDataKeyIdentifierClause.cs / 1 / X509RawDataKeyIdentifierClause.cs

                            //------------------------------------------------------------ 
// Copyright (c) Microsoft Corporation.  All rights reserved.
//-----------------------------------------------------------

namespace System.IdentityModel.Tokens 
{
    using System.Globalization; 
    using System.Security.Cryptography.X509Certificates; 

    public class X509RawDataKeyIdentifierClause : BinaryKeyIdentifierClause 
    {
        X509Certificate2 certificate;
        X509AsymmetricSecurityKey key;
 
        public X509RawDataKeyIdentifierClause(X509Certificate2 certificate)
            : this(GetRawData(certificate), false) 
        { 
            this.certificate = certificate;
        } 

        public X509RawDataKeyIdentifierClause(byte[] certificateRawData)
            : this(certificateRawData, true)
        { 
        }
 
        internal X509RawDataKeyIdentifierClause(byte[] certificateRawData, bool cloneBuffer) 
            : base(null, certificateRawData, cloneBuffer)
        { 
        }

        public override bool CanCreateKey
        { 
            get { return true; }
        } 
 
        public override SecurityKey CreateKey()
        { 
            if (this.key == null)
            {
                if (this.certificate == null)
                { 
                    this.certificate = new X509Certificate2(GetBuffer());
                } 
                this.key = new X509AsymmetricSecurityKey(this.certificate); 
            }
            return this.key; 
        }

        static byte[] GetRawData(X509Certificate certificate)
        { 
            if (certificate == null)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("certificate"); 
 
            return certificate.GetRawCertData();
        } 

        public byte[] GetX509RawData()
        {
            return GetBuffer(); 
        }
 
        public bool Matches(X509Certificate2 certificate) 
        {
            if (certificate == null) 
                return false;

            return Matches(GetRawData(certificate));
        } 

        public override string ToString() 
        { 
            return string.Format(CultureInfo.InvariantCulture, "X509RawDataKeyIdentifierClause(RawData = {0})", ToBase64String());
        } 
    }
}

// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
                        

Link Menu

Network programming in C#, Network Programming in VB.NET, Network Programming in .NET
This book is available now!
Buy at Amazon US or
Buy at Amazon UK