当前位置: 首页>>代码示例>>C#>>正文


C# Cryptography.SafeProvHandle类代码示例

本文整理汇总了C#中System.Security.Cryptography.SafeProvHandle的典型用法代码示例。如果您正苦于以下问题:C# SafeProvHandle类的具体用法?C# SafeProvHandle怎么用?C# SafeProvHandle使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SafeProvHandle类属于System.Security.Cryptography命名空间,在下文中一共展示了SafeProvHandle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Dispose

        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                SafeKeyHandle hKey = _hKey;
                _hKey = null;
                if (hKey != null)
                {
                    hKey.Dispose();
                }

                SafeProvHandle hProvider = _hProvider;
                _hProvider = null;
                if (hProvider != null)
                {
                    hProvider.Dispose();
                }
            }

            base.Dispose(disposing);
        }
开发者ID:dotnet,项目名称:corefx,代码行数:21,代码来源:BasicSymmetricCipherCsp.cs

示例2: OpenCSP

        /// <summary>
        /// OpenCSP performs the core work of opening and creating CSPs and containers in CSPs
        /// </summary>
        public static int OpenCSP(CspParameters cspParameters, uint flags, out SafeProvHandle safeProvHandle)
        {
            string providerName = null;
            string containerName = null;
            if (null == cspParameters)
            {
                throw new ArgumentException(SR.Format(SR.CspParameter_invalid, "cspParameters"));
            }

            //look for provider type in the cspParameters
            int providerType = cspParameters.ProviderType;

            //look for provider name in the cspParamters 
            //if CSP provider is not null then use the provider name from cspParameters
            if (null != cspParameters.ProviderName)
            {
                providerName = cspParameters.ProviderName;
            }
            else //Get the default provider name
            {
                providerName = GetDefaultProvider(providerType);
                cspParameters.ProviderName = providerName;
            }
            // look to see if the user specified that we should pass
            // CRYPT_MACHINE_KEYSET to CAPI to use machine key storage instead
            // of user key storage
            int cspProviderFlags = (int)cspParameters.Flags;

            // If the user specified CSP_PROVIDER_FLAGS_USE_DEFAULT_KEY_CONTAINER,
            // then ignore the key container name and hand back the default container
            if (!IsFlagBitSet((uint)cspProviderFlags, (uint)CspProviderFlags.UseDefaultKeyContainer))
            {
                //look for key container name in the cspParameters 
                if (null != cspParameters.KeyContainerName)
                {
                    containerName = cspParameters.KeyContainerName;
                }
            }

            SafeProvHandle hProv;

            // Go ahead and try to open the CSP.  If we fail, make sure the CSP
            // returned is 0 as that is going to be the error check in the caller.
            flags |= MapCspProviderFlags((int)cspParameters.Flags);
            if (S_OK != AcquireCryptContext(out hProv, containerName, providerName, providerType, flags))
            {
                hProv.Dispose();
                safeProvHandle = SafeProvHandle.InvalidHandle;
                return GetErrorCode();
            }

            hProv.ContainerName = containerName;
            hProv.ProviderName = providerName;
            hProv.Types = providerType;
            hProv.Flags = flags;

            // We never want to delete a key container if it's already there.
            if (IsFlagBitSet(flags, (uint)CryptAcquireContextFlags.CRYPT_VERIFYCONTEXT))
            {
                hProv.PersistKeyInCsp = false;
            }

            safeProvHandle = hProv;
            return S_OK;
        }
开发者ID:SGuyGe,项目名称:corefx,代码行数:68,代码来源:CapiHelper.cs

示例3: AcquireCsp

        /// <summary>
        /// This method opens the CSP using CRYPT_VERIFYCONTEXT
        /// KeyContainer must be null for the flag CRYPT_VERIFYCONTEXT
        /// This method asserts if keyContainer is not null
        /// </summary>
        /// <param name="cspParameters">CSPParameter to use</param>
        /// <param name="safeProvHandle">Safe provider handle</param>
        internal static void AcquireCsp(CspParameters cspParameters, out SafeProvHandle safeProvHandle)
        {
            Debug.Assert(cspParameters != null);
            Debug.Assert(cspParameters.KeyContainerName == null);

            SafeProvHandle hProv;
            //
            // We want to just open this CSP.  Passing in verify context will
            // open it and, if a container is given, map to open the container.
            //
            int ret = OpenCSP(cspParameters, (uint)CryptAcquireContextFlags.CRYPT_VERIFYCONTEXT, out hProv);
            if (S_OK != ret)
            {
                hProv.Dispose();
                throw new CryptographicException(SR.Format(SR.OpenCSP_Failed, Convert.ToString(ret)));
            }

            safeProvHandle = hProv;
        }
开发者ID:SGuyGe,项目名称:corefx,代码行数:26,代码来源:CapiHelper.cs

示例4: CryptAcquireContext

 public static extern bool CryptAcquireContext(out SafeProvHandle psafeProvHandle, string pszContainer,
                                                 string pszProvider, int dwProvType, uint dwFlags);
开发者ID:SGuyGe,项目名称:corefx,代码行数:2,代码来源:CapiHelper.cs

示例5: GetNonZeroBytes

 private static extern void GetNonZeroBytes(SafeProvHandle hProv, byte[] randomBytes, int count);
开发者ID:destinyclown,项目名称:coreclr,代码行数:1,代码来源:RNGCryptoServiceProvider.cs

示例6: SetPersistKeyInCsp

 /// <summary>
 /// Sets the PersistKeyInCsp
 /// </summary>
 /// <param name="safeProvHandle">Safe Prov Handle. Expects a valid handle</param>
 /// <param name="fPersistKeyInCsp">Sets the PersistKeyInCsp value</param>
 internal static void SetPersistKeyInCsp(SafeProvHandle safeProvHandle, bool fPersistKeyInCsp)
 {
     VerifyValidHandle(safeProvHandle);
     safeProvHandle.PersistKeyInCsp = fPersistKeyInCsp;
 }
开发者ID:SGuyGe,项目名称:corefx,代码行数:10,代码来源:CapiHelper.cs

示例7: GetKeyPairHelper

        /// <summary>
        /// Helper function to get the key pair
        /// </summary>
        internal static SafeKeyHandle GetKeyPairHelper(
            CspAlgorithmType keyType,
            CspParameters parameters,
            int keySize,
            SafeProvHandle safeProvHandle)
        {
            // If the key already exists, use it, else generate a new one
            SafeKeyHandle hKey;
            int hr = CapiHelper.GetUserKey(safeProvHandle, parameters.KeyNumber, out hKey);
            if (hr != S_OK)
            {
                hKey.Dispose();
                if (IsFlagBitSet((uint)parameters.Flags, (uint)CspProviderFlags.UseExistingKey) ||
                                                         (uint)hr != (uint)CryptKeyError.NTE_NO_KEY)
                {
                    throw new CryptographicException(SR.Format(SR.CryptGetUserKey_Failed, Convert.ToString(hr)));
                }

                // GenerateKey will check for failures and throw an exception
                CapiHelper.GenerateKey(safeProvHandle, parameters.KeyNumber, (int)parameters.Flags,
                                        (uint)keySize, out hKey);
            }

            // check that this is indeed an RSA/DSS key.
            byte[] algid = CapiHelper.GetKeyParameter(hKey, Constants.CLR_ALGID);

            int dwAlgId = (algid[0] | (algid[1] << 8) | (algid[2] << 16) | (algid[3] << 24));

            if ((keyType == CspAlgorithmType.Rsa && dwAlgId != CALG_RSA_KEYX && dwAlgId != CALG_RSA_SIGN) ||
                (keyType == CspAlgorithmType.Dss && dwAlgId != CALG_DSS_SIGN))
            {
                hKey.Dispose();
                throw new CryptographicException(SR.Format(SR.Cryptography_CSP_WrongKeySpec, Convert.ToString(keyType)));
            }

            return hKey;
        }
开发者ID:SGuyGe,项目名称:corefx,代码行数:40,代码来源:CapiHelper.cs

示例8: GetUserKey

 /// <summary>
 /// Retrieves the handle for user public / private key pair. 
 /// </summary>
 internal static int GetUserKey(SafeProvHandle safeProvHandle, int keySpec, out SafeKeyHandle safeKeyHandle)
 {
     int hr = S_OK;
     VerifyValidHandle(safeProvHandle);
     if (!Interop.CryptGetUserKey(safeProvHandle, keySpec, out safeKeyHandle))
     {
         hr = GetErrorCode();
     }
     if (hr == S_OK)
     {
         safeKeyHandle.KeySpec = keySpec;
     }
     return hr;
 }
开发者ID:SGuyGe,项目名称:corefx,代码行数:17,代码来源:CapiHelper.cs

示例9: CryptGetUserKey

            public static bool CryptGetUserKey(
                SafeProvHandle safeProvHandle,
                int dwKeySpec,
                out SafeKeyHandle safeKeyHandle)
            {
                bool response = _CryptGetUserKey(safeProvHandle, dwKeySpec, out safeKeyHandle);

                safeKeyHandle.SetParent(safeProvHandle);

                return response;
            }
开发者ID:SGuyGe,项目名称:corefx,代码行数:11,代码来源:CapiHelper.cs

示例10: _CryptCreateHash

 private static extern bool _CryptCreateHash(SafeProvHandle hProv, int algId, SafeKeyHandle hKey, CryptCreateHashFlags dwFlags, out SafeHashHandle phHash);
开发者ID:SGuyGe,项目名称:corefx,代码行数:1,代码来源:CapiHelper.cs

示例11: _CryptImportKey

 private static extern bool _CryptImportKey(SafeProvHandle hProv, byte[] pbData, int dwDataLen, SafeKeyHandle hPubKey, int dwFlags, out SafeKeyHandle phKey);
开发者ID:SGuyGe,项目名称:corefx,代码行数:1,代码来源:CapiHelper.cs

示例12: _CryptGenKey

 private static extern bool _CryptGenKey(SafeProvHandle safeProvHandle, int Algid, int dwFlags, out SafeKeyHandle safeKeyHandle);
开发者ID:SGuyGe,项目名称:corefx,代码行数:1,代码来源:CapiHelper.cs

示例13: _CryptGetUserKey

 private static extern bool _CryptGetUserKey(SafeProvHandle safeProvHandle, int dwKeySpec, out SafeKeyHandle safeKeyHandle);
开发者ID:SGuyGe,项目名称:corefx,代码行数:1,代码来源:CapiHelper.cs

示例14: CryptSetProvParam

 public static extern bool CryptSetProvParam(SafeProvHandle safeProvHandle, CryptGetProvParam dwParam, ref IntPtr pbData, int dwFlags);
开发者ID:SGuyGe,项目名称:corefx,代码行数:1,代码来源:CapiHelper.cs

示例15: CryptGetProvParam

 public static extern bool CryptGetProvParam(SafeProvHandle safeProvHandle, int dwParam, byte[] pbData,
                                             ref int dwDataLen, int dwFlags);
开发者ID:SGuyGe,项目名称:corefx,代码行数:2,代码来源:CapiHelper.cs


注:本文中的System.Security.Cryptography.SafeProvHandle类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。