// // 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; } }
// // 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(); } } }
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); }
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; } }
// // 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(); } } }