示例#1
0
        //
        // Summary:
        //  Creates a new InfoCardKeyedHashAlgorithm based on a SymmetricCryptoHandle.
        //
        // Parameters:
        //  cryptoHandle  - The handle to the symmetric key on which to base the keyed hash.
        //
        public InfoCardKeyedHashAlgorithm(SymmetricCryptoHandle cryptoHandle)
        {
            InternalRefCountedHandle nativeHandle = null;

            try
            {
                //
                // Call native api to get a hashCryptoHandle.
                //
                int status = CardSpaceSelector.GetShim().m_csShimGetKeyedHash(cryptoHandle.InternalHandle, out nativeHandle);

                if (0 != status)
                {
                    IDT.CloseInvalidOutSafeHandle(nativeHandle);
                    ExceptionHelper.ThrowIfCardSpaceException(status);
                    throw IDT.ThrowHelperError(new Win32Exception(status));
                }

                m_cryptoHandle = (HashCryptoHandle)CryptoHandle.Create(nativeHandle);

                m_param = (RpcHashCryptoParameters)m_cryptoHandle.Parameters;
            }
            catch
            {
                if (null != m_cryptoHandle)
                {
                    m_cryptoHandle.Dispose();
                }
                throw;
            }
        }
        //
        // Summary:
        //  Creates a new InfoCardKeyedHashAlgorithm based on a SymmetricCryptoHandle.
        //
        // Parameters:
        //  cryptoHandle  - The handle to the symmetric key on which to base the keyed hash.
        //
        public InfoCardKeyedHashAlgorithm(SymmetricCryptoHandle cryptoHandle)
        {
            InternalRefCountedHandle nativeHandle = null;

            try
            {
                //
                // Call native api to get a hashCryptoHandle.
                //
                int status = CardSpaceSelector.GetShim().m_csShimGetKeyedHash(cryptoHandle.InternalHandle, out nativeHandle);

                if (0 != status)
                {
                    IDT.CloseInvalidOutSafeHandle(nativeHandle);
                    ExceptionHelper.ThrowIfCardSpaceException(status);
                    throw IDT.ThrowHelperError(new Win32Exception(status));
                }

                m_cryptoHandle = (HashCryptoHandle)CryptoHandle.Create(nativeHandle);

                m_param = (RpcHashCryptoParameters)m_cryptoHandle.Parameters;
            }
            catch
            {

                if (null != m_cryptoHandle)
                {
                    m_cryptoHandle.Dispose();
                }
                throw;
            }

        }
        public InfoCardKeyedHashAlgorithm(SymmetricCryptoHandle cryptoHandle)
        {
            InternalRefCountedHandle nativeHashHandle = null;

            try
            {
                int status = CardSpaceSelector.GetShim().m_csShimGetKeyedHash(cryptoHandle.InternalHandle, out nativeHashHandle);
                if (status != 0)
                {
                    InfoCardTrace.CloseInvalidOutSafeHandle(nativeHashHandle);
                    ExceptionHelper.ThrowIfCardSpaceException(status);
                    throw InfoCardTrace.ThrowHelperError(new Win32Exception(status));
                }
                this.m_cryptoHandle = (HashCryptoHandle)CryptoHandle.Create(nativeHashHandle);
                this.m_param        = (RpcHashCryptoParameters)this.m_cryptoHandle.Parameters;
            }
            catch
            {
                if (this.m_cryptoHandle != null)
                {
                    this.m_cryptoHandle.Dispose();
                }
                throw;
            }
        }
 //
 // IDisposable
 //
 public void Dispose()
 {
     if (null != m_cryptoHandle)
     {
         m_cryptoHandle.Dispose();
         m_cryptoHandle = null;
     }
 }
 public void Dispose()
 {
     if (this.m_cryptoHandle != null)
     {
         this.m_cryptoHandle.Dispose();
         this.m_cryptoHandle = null;
     }
 }
 public void Dispose()
 {
     if (this.m_cryptoHandle != null)
     {
         this.m_cryptoHandle.Dispose();
         this.m_cryptoHandle = null;
     }
 }
        //
        // Summary:
        //  Given a pointer to a native cryptosession this method creates the appropriate CryptoHandle type.
        //
        static internal CryptoHandle Create(InternalRefCountedHandle nativeHandle)
        {
            CryptoHandle handle = null;

            bool mustRelease = false;

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                nativeHandle.DangerousAddRef(ref mustRelease);
                RpcInfoCardCryptoHandle hCrypto =
                    (RpcInfoCardCryptoHandle)Marshal.PtrToStructure(nativeHandle.DangerousGetHandle(),
                                                                    typeof(RpcInfoCardCryptoHandle));
                DateTime expiration = DateTime.FromFileTimeUtc(hCrypto.expiration);

                switch (hCrypto.type)
                {
                case RpcInfoCardCryptoHandle.HandleType.Asymmetric:
                    handle = new AsymmetricCryptoHandle(nativeHandle, expiration, hCrypto.cryptoParameters);
                    break;

                case RpcInfoCardCryptoHandle.HandleType.Symmetric:
                    handle = new SymmetricCryptoHandle(nativeHandle, expiration, hCrypto.cryptoParameters);
                    break;

                case RpcInfoCardCryptoHandle.HandleType.Transform:
                    handle = new TransformCryptoHandle(nativeHandle, expiration, hCrypto.cryptoParameters);
                    break;

                case RpcInfoCardCryptoHandle.HandleType.Hash:
                    handle = new HashCryptoHandle(nativeHandle, expiration, hCrypto.cryptoParameters);
                    break;

                default:
                    IDT.DebugAssert(false, "Invalid crypto operation type");
                    throw IDT.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.GeneralExceptionMessage)));
                }

                return(handle);
            }
            finally
            {
                if (mustRelease)
                {
                    nativeHandle.DangerousRelease();
                }
            }
        }
 public InfoCardSymmetricCrypto(SymmetricCryptoHandle cryptoHandle)
 {
     this.m_cryptoHandle = (SymmetricCryptoHandle)cryptoHandle.Duplicate();
     try
     {
         this.m_params = (RpcSymmetricCryptoParameters)this.m_cryptoHandle.Parameters;
     }
     catch
     {
         if (this.m_cryptoHandle != null)
         {
             this.m_cryptoHandle.Dispose();
             this.m_cryptoHandle = null;
         }
         throw;
     }
 }
 public InfoCardSymmetricCrypto(SymmetricCryptoHandle cryptoHandle)
 {
     this.m_cryptoHandle = (SymmetricCryptoHandle) cryptoHandle.Duplicate();
     try
     {
         this.m_params = (RpcSymmetricCryptoParameters) this.m_cryptoHandle.Parameters;
     }
     catch
     {
         if (this.m_cryptoHandle != null)
         {
             this.m_cryptoHandle.Dispose();
             this.m_cryptoHandle = null;
         }
         throw;
     }
 }
 public InfoCardSymmetricAlgorithm(SymmetricCryptoHandle cryptoHandle)
 {
     this.m_cryptoHandle = (SymmetricCryptoHandle)cryptoHandle.Duplicate();
     try
     {
         this.m_parameters         = (RpcSymmetricCryptoParameters)this.m_cryptoHandle.Parameters;
         base.KeySizeValue         = this.m_parameters.keySize;
         base.BlockSizeValue       = this.m_parameters.blockSize;
         base.FeedbackSizeValue    = this.m_parameters.feedbackSize;
         base.LegalBlockSizesValue = new KeySizes[] { new KeySizes(base.BlockSizeValue, base.BlockSizeValue, 0) };
         base.LegalKeySizesValue   = new KeySizes[] { new KeySizes(base.KeySizeValue, base.KeySizeValue, 0) };
     }
     catch
     {
         this.m_cryptoHandle.Dispose();
         throw;
     }
 }
 public InfoCardSymmetricAlgorithm(SymmetricCryptoHandle cryptoHandle)
 {
     this.m_cryptoHandle = (SymmetricCryptoHandle) cryptoHandle.Duplicate();
     try
     {
         this.m_parameters = (RpcSymmetricCryptoParameters) this.m_cryptoHandle.Parameters;
         base.KeySizeValue = this.m_parameters.keySize;
         base.BlockSizeValue = this.m_parameters.blockSize;
         base.FeedbackSizeValue = this.m_parameters.feedbackSize;
         base.LegalBlockSizesValue = new KeySizes[] { new KeySizes(base.BlockSizeValue, base.BlockSizeValue, 0) };
         base.LegalKeySizesValue = new KeySizes[] { new KeySizes(base.KeySizeValue, base.KeySizeValue, 0) };
     }
     catch
     {
         this.m_cryptoHandle.Dispose();
         throw;
     }
 }
        internal static CryptoHandle Create(InternalRefCountedHandle nativeHandle)
        {
            CryptoHandle handle = null;
            CryptoHandle handle3;
            bool         success = false;

            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                nativeHandle.DangerousAddRef(ref success);
                RpcInfoCardCryptoHandle handle2 = (RpcInfoCardCryptoHandle)Marshal.PtrToStructure(nativeHandle.DangerousGetHandle(), typeof(RpcInfoCardCryptoHandle));
                DateTime expiration             = DateTime.FromFileTimeUtc(handle2.expiration);
                switch (handle2.type)
                {
                case RpcInfoCardCryptoHandle.HandleType.Asymmetric:
                    handle = new AsymmetricCryptoHandle(nativeHandle, expiration, handle2.cryptoParameters);
                    break;

                case RpcInfoCardCryptoHandle.HandleType.Symmetric:
                    handle = new SymmetricCryptoHandle(nativeHandle, expiration, handle2.cryptoParameters);
                    break;

                case RpcInfoCardCryptoHandle.HandleType.Transform:
                    handle = new TransformCryptoHandle(nativeHandle, expiration, handle2.cryptoParameters);
                    break;

                case RpcInfoCardCryptoHandle.HandleType.Hash:
                    handle = new HashCryptoHandle(nativeHandle, expiration, handle2.cryptoParameters);
                    break;

                default:
                    throw InfoCardTrace.ThrowHelperError(new InvalidOperationException(Microsoft.InfoCards.SR.GetString("GeneralExceptionMessage")));
                }
                handle3 = handle;
            }
            finally
            {
                if (success)
                {
                    nativeHandle.DangerousRelease();
                }
            }
            return(handle3);
        }
        //
        // Summary:
        //  Creates a new InfoCardSymmetricCrypto based on a SymmetricCryptoHandle
        //
        // Parameters:
        //  cryptoHandle  - A handle to the symmetric key on which to base this object.
        //
        public InfoCardSymmetricCrypto(SymmetricCryptoHandle cryptoHandle)
            : base()
        {
            m_cryptoHandle = (SymmetricCryptoHandle)cryptoHandle.Duplicate();

            try
            {
                m_params = (RpcSymmetricCryptoParameters)m_cryptoHandle.Parameters;
            }
            catch
            {
                if (null != m_cryptoHandle)
                {
                    m_cryptoHandle.Dispose();
                    m_cryptoHandle = null;
                }
                throw;
            }
        }
        //
        // Summary:
        //  Creates a new InfoCardSymmetricCrypto based on a SymmetricCryptoHandle
        //
        // Parameters:
        //  cryptoHandle  - A handle to the symmetric key on which to base this object.
        //
        public InfoCardSymmetricCrypto(SymmetricCryptoHandle cryptoHandle)
            : base()
        {
            m_cryptoHandle = (SymmetricCryptoHandle)cryptoHandle.Duplicate();

            try
            {
                m_params = (RpcSymmetricCryptoParameters)m_cryptoHandle.Parameters;
            }
            catch
            {
                if (null != m_cryptoHandle)
                {
                    m_cryptoHandle.Dispose();
                    m_cryptoHandle = null;
                }
                throw;
            }
        }
        //
        // Summary:
        //  Constructs an InfoCardSymmetricAlgorithm
        //
        // Parameters:
        //  cryptoHandle  - A handle to the symmetric key to base the symmetric algorithm on.
        //
        public InfoCardSymmetricAlgorithm(SymmetricCryptoHandle cryptoHandle)
            : base()
        {
            m_cryptoHandle = (SymmetricCryptoHandle)cryptoHandle.Duplicate();

            try
            {
                m_parameters = (RpcSymmetricCryptoParameters)m_cryptoHandle.Parameters;

                KeySizeValue = m_parameters.keySize;
                BlockSizeValue = m_parameters.blockSize;
                FeedbackSizeValue = m_parameters.feedbackSize;
                LegalBlockSizesValue = new KeySizes[] { new KeySizes(BlockSizeValue, BlockSizeValue, 0) };
                LegalKeySizesValue = new KeySizes[] { new KeySizes(KeySizeValue, KeySizeValue, 0) };
            }
            catch
            {
                m_cryptoHandle.Dispose();
                throw;
            }
        }
        //
        // Summary:
        //  Constructs an InfoCardSymmetricAlgorithm
        //
        // Parameters:
        //  cryptoHandle  - A handle to the symmetric key to base the symmetric algorithm on.
        //
        public InfoCardSymmetricAlgorithm(SymmetricCryptoHandle cryptoHandle)
            : base()
        {
            m_cryptoHandle = (SymmetricCryptoHandle)cryptoHandle.Duplicate();

            try
            {
                m_parameters = (RpcSymmetricCryptoParameters)m_cryptoHandle.Parameters;

                KeySizeValue         = m_parameters.keySize;
                BlockSizeValue       = m_parameters.blockSize;
                FeedbackSizeValue    = m_parameters.feedbackSize;
                LegalBlockSizesValue = new KeySizes[] { new KeySizes(BlockSizeValue, BlockSizeValue, 0) };
                LegalKeySizesValue   = new KeySizes[] { new KeySizes(KeySizeValue, KeySizeValue, 0) };
            }
            catch
            {
                m_cryptoHandle.Dispose();
                throw;
            }
        }
 public InfoCardKeyedHashAlgorithm(SymmetricCryptoHandle cryptoHandle)
 {
     InternalRefCountedHandle nativeHashHandle = null;
     try
     {
         int status = CardSpaceSelector.GetShim().m_csShimGetKeyedHash(cryptoHandle.InternalHandle, out nativeHashHandle);
         if (status != 0)
         {
             InfoCardTrace.CloseInvalidOutSafeHandle(nativeHashHandle);
             ExceptionHelper.ThrowIfCardSpaceException(status);
             throw InfoCardTrace.ThrowHelperError(new Win32Exception(status));
         }
         this.m_cryptoHandle = (HashCryptoHandle) CryptoHandle.Create(nativeHashHandle);
         this.m_param = (RpcHashCryptoParameters) this.m_cryptoHandle.Parameters;
     }
     catch
     {
         if (this.m_cryptoHandle != null)
         {
             this.m_cryptoHandle.Dispose();
         }
         throw;
     }
 }
 public InfoCardProofToken(SymmetricCryptoHandle cryptoHandle, DateTime expiration) : this(expiration)
 {
     this.InitCrypto(new InfoCardSymmetricCrypto(cryptoHandle));
 }
 //
 // IDisposable
 //
 public void Dispose()
 {
     if (null != m_cryptoHandle)
     {
         m_cryptoHandle.Dispose();
         m_cryptoHandle = null;
     }
 }
 public InfoCardProofToken(SymmetricCryptoHandle cryptoHandle, DateTime expiration) : this( expiration )
 {
     InitCrypto(new InfoCardSymmetricCrypto(cryptoHandle));
 }
示例#21
0
        //
        // Summary:
        //  Given a pointer to a native cryptosession this method creates the appropriate CryptoHandle type.
        //
        static internal CryptoHandle Create(InternalRefCountedHandle nativeHandle)
        {
            CryptoHandle handle = null;

            bool mustRelease = false;
            RuntimeHelpers.PrepareConstrainedRegions();
            try
            {
                nativeHandle.DangerousAddRef(ref mustRelease);
                RpcInfoCardCryptoHandle hCrypto =
                    (RpcInfoCardCryptoHandle)Marshal.PtrToStructure(nativeHandle.DangerousGetHandle(),
                                                                     typeof(RpcInfoCardCryptoHandle));
                DateTime expiration = DateTime.FromFileTimeUtc(hCrypto.expiration);

                switch (hCrypto.type)
                {
                    case RpcInfoCardCryptoHandle.HandleType.Asymmetric:
                        handle = new AsymmetricCryptoHandle(nativeHandle, expiration, hCrypto.cryptoParameters);
                        break;
                    case RpcInfoCardCryptoHandle.HandleType.Symmetric:
                        handle = new SymmetricCryptoHandle(nativeHandle, expiration, hCrypto.cryptoParameters);
                        break;
                    case RpcInfoCardCryptoHandle.HandleType.Transform:
                        handle = new TransformCryptoHandle(nativeHandle, expiration, hCrypto.cryptoParameters);
                        break;
                    case RpcInfoCardCryptoHandle.HandleType.Hash:
                        handle = new HashCryptoHandle(nativeHandle, expiration, hCrypto.cryptoParameters);
                        break;
                    default:
                        IDT.DebugAssert(false, "Invalid crypto operation type");
                        throw IDT.ThrowHelperError(new InvalidOperationException(SR.GetString(SR.GeneralExceptionMessage)));
                }

                return handle;

            }
            finally
            {
                if (mustRelease)
                {
                    nativeHandle.DangerousRelease();
                }
            }
        }