RemoteAsymmetricSignatureFormatter.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 / infocard / Service / managed / Microsoft / InfoCards / RemoteAsymmetricSignatureFormatter.cs / 1 / RemoteAsymmetricSignatureFormatter.cs

                            //------------------------------------------------------------------------------ 
// Copyright (c) Microsoft Corporation.  All rights reserved.
//-----------------------------------------------------------------------------
namespace Microsoft.InfoCards
{ 
    using System;
    using System.Security.Cryptography; 
    using System.Security.Cryptography.X509Certificates; 
    using System.ServiceModel;
    using System.ServiceModel.Security; 
    using System.ServiceModel.Security.Tokens;

    using IDT = Microsoft.InfoCards.Diagnostics.InfoCardTrace;
 
    //
    // Summary: 
    //  Signature formater for use with RemoteCryptoRsaServiceProvider 
    //
    class RemoteAsymmetricSignatureFormatter : AsymmetricSignatureFormatter 
    {
        RemoteCryptoRsaServiceProvider  m_rsa;
        string                          m_hashOidString;
        int                             m_nativeHashType; 

        public RemoteAsymmetricSignatureFormatter() 
            : base() 
        {
        } 

        //
        // Summary:
        //  Create the new signature. 
        //
        // Arguments: 
        //  rgbHash:    the hash value to sign. 
        //
        // Returns: 
        //  The signature value.
        //
        public override byte[] CreateSignature(byte[] rgbHash)
        { 
            if( null == m_rsa )
            { 
                throw IDT.ThrowHelperError( new ArgumentException( "m_rsa" ) ); 
            }
            if( String.IsNullOrEmpty( m_hashOidString ) ) 
            {
                throw IDT.ThrowHelperError( new ArgumentException( "m_hashOidString" ) );
            }
            if( null == rgbHash ) 
            {
                throw IDT.ThrowHelperError( new ArgumentNullException( "rgbHash" ) ); 
            } 

            byte[] signature = m_rsa.SignHash( m_nativeHashType, rgbHash ); 

            return signature;
        }
 
        //
        // Summary: 
        //  Sets the hash algorithm 
        //
        // Arguments: 
        //  strName:    the string name of the algorithm.
        //
        public override void SetHashAlgorithm(string strName)
        { 
            m_hashOidString = CryptoConfig.MapNameToOID( strName );
            m_nativeHashType = NativeMcppMethods.CryptAlgIdFromOid( m_hashOidString ); 
        } 

        // 
        // Summary:
        //  Set the current ket set for use in signing.
        //
        // Arguments: 
        //  key:        The key to use.  Must be a RemoteCryptoRsaServiceProvider instance.
        // 
        public override void SetKey(AsymmetricAlgorithm key) 
        {
            m_rsa = key as RemoteCryptoRsaServiceProvider; 
            if( null == m_rsa )
            {
                throw IDT.ThrowHelperError( new NotSupportedException() );
            } 
        }
 
 
    }
} 

// 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