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


C# Cryptography.SafeKeyHandle类代码示例

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


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

示例1: GetKeyPairHelper

 internal static void GetKeyPairHelper(CspAlgorithmType keyType, CspParameters parameters, bool randomKeyContainer, int dwKeySize, ref SafeProvHandle safeProvHandle, ref SafeKeyHandle safeKeyHandle)
 {
     SafeProvHandle hProv = CreateProvHandle(parameters, randomKeyContainer);
     if (parameters.CryptoKeySecurity != null)
     {
         KeyContainerPermission permission = new KeyContainerPermission(KeyContainerPermissionFlags.NoFlags);
         KeyContainerPermissionAccessEntry accessEntry = new KeyContainerPermissionAccessEntry(parameters, KeyContainerPermissionFlags.ChangeAcl);
         permission.AccessEntries.Add(accessEntry);
         permission.Demand();
         SetKeySetSecurityInfo(hProv, parameters.CryptoKeySecurity, parameters.CryptoKeySecurity.ChangedAccessControlSections);
     }
     if (parameters.ParentWindowHandle != IntPtr.Zero)
     {
         SetProviderParameter(hProv, parameters.KeyNumber, 10, parameters.ParentWindowHandle);
     }
     else if (parameters.KeyPassword != null)
     {
         IntPtr pbData = Marshal.SecureStringToCoTaskMemAnsi(parameters.KeyPassword);
         try
         {
             SetProviderParameter(hProv, parameters.KeyNumber, 11, pbData);
         }
         finally
         {
             if (pbData != IntPtr.Zero)
             {
                 Marshal.ZeroFreeCoTaskMemAnsi(pbData);
             }
         }
     }
     safeProvHandle = hProv;
     SafeKeyHandle invalidHandle = SafeKeyHandle.InvalidHandle;
     int hr = _GetUserKey(safeProvHandle, parameters.KeyNumber, ref invalidHandle);
     if (hr != 0)
     {
         if (((parameters.Flags & CspProviderFlags.UseExistingKey) != CspProviderFlags.NoFlags) || (hr != -2146893811))
         {
             throw new CryptographicException(hr);
         }
         _GenerateKey(safeProvHandle, parameters.KeyNumber, parameters.Flags, dwKeySize, ref invalidHandle);
     }
     byte[] buffer = _GetKeyParameter(invalidHandle, 9);
     int num2 = ((buffer[0] | (buffer[1] << 8)) | (buffer[2] << 0x10)) | (buffer[3] << 0x18);
     if ((((keyType == CspAlgorithmType.Rsa) && (num2 != 0xa400)) && (num2 != 0x2400)) || ((keyType == CspAlgorithmType.Dss) && (num2 != 0x2200)))
     {
         invalidHandle.Dispose();
         throw new CryptographicException(Environment.GetResourceString("Cryptography_CSP_WrongKeySpec"));
     }
     safeKeyHandle = invalidHandle;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:50,代码来源:Utils.cs

示例2: _ExportKey

 internal static extern void _ExportKey(SafeKeyHandle hKey, int blobType, object cspObject);
开发者ID:peterdocter,项目名称:referencesource,代码行数:1,代码来源:utils.cs

示例3: ImportCspBlobHelper

        [System.Security.SecurityCritical]  // auto-generated
        internal static void ImportCspBlobHelper (CspAlgorithmType keyType, byte[] keyBlob, bool publicOnly, ref CspParameters parameters, bool randomKeyContainer, ref SafeProvHandle safeProvHandle, ref SafeKeyHandle safeKeyHandle) {
            // Free the current key handle
            if (safeKeyHandle != null && !safeKeyHandle.IsClosed)
                safeKeyHandle.Dispose();
            safeKeyHandle = SafeKeyHandle.InvalidHandle;

            if (publicOnly) {
                parameters.KeyNumber = Utils._ImportCspBlob(keyBlob, keyType == CspAlgorithmType.Dss ? Utils.StaticDssProvHandle : Utils.StaticProvHandle, (CspProviderFlags) 0, ref safeKeyHandle);
            } else {
                if (!CompatibilitySwitches.IsAppEarlierThanWindowsPhone8) {
                    KeyContainerPermission kp = new KeyContainerPermission(KeyContainerPermissionFlags.NoFlags);
                    KeyContainerPermissionAccessEntry entry = new KeyContainerPermissionAccessEntry(parameters, KeyContainerPermissionFlags.Import);
                    kp.AccessEntries.Add(entry);
                    kp.Demand();
                }
                if (safeProvHandle == null)
                    safeProvHandle = Utils.CreateProvHandle(parameters, randomKeyContainer);
                parameters.KeyNumber = Utils._ImportCspBlob(keyBlob, safeProvHandle, parameters.Flags, ref safeKeyHandle);
            }
        }
开发者ID:peterdocter,项目名称:referencesource,代码行数:21,代码来源:utils.cs

示例4: EncryptKey

 private static extern void EncryptKey(SafeKeyHandle pKeyContext,
                                       [MarshalAs(UnmanagedType.LPArray)] byte[] pbKey,
                                       int cbKey,
                                       [MarshalAs(UnmanagedType.Bool)] bool fOAEP,
                                       ObjectHandleOnStack ohRetEncryptedKey);
开发者ID:l1183479157,项目名称:coreclr,代码行数:5,代码来源:RSACryptoServiceProvider.cs

示例5: _ImportCspBlob

 internal static extern int _ImportCspBlob(byte[] keyBlob, SafeProvHandle hProv, CspProviderFlags flags, ref SafeKeyHandle hKey);
开发者ID:peterdocter,项目名称:referencesource,代码行数:1,代码来源:utils.cs

示例6: ExportCspBlobHelper

 [System.Security.SecurityCritical]  // auto-generated
 internal static byte[] ExportCspBlobHelper (bool includePrivateParameters, CspParameters parameters, SafeKeyHandle safeKeyHandle) {
     if (includePrivateParameters) {
         if (!CompatibilitySwitches.IsAppEarlierThanWindowsPhone8) {
             KeyContainerPermission kp = new KeyContainerPermission(KeyContainerPermissionFlags.NoFlags);
             KeyContainerPermissionAccessEntry entry = new KeyContainerPermissionAccessEntry(parameters, KeyContainerPermissionFlags.Export);
             kp.AccessEntries.Add(entry);
             kp.Demand();
         }
     }
     byte[] blob = null;
     Utils.ExportCspBlob(safeKeyHandle, includePrivateParameters ? Constants.PRIVATEKEYBLOB : Constants.PUBLICKEYBLOB, JitHelpers.GetObjectHandleOnStack(ref blob));
     return blob;
 }
开发者ID:peterdocter,项目名称:referencesource,代码行数:14,代码来源:utils.cs

示例7: SetKeyParamDw

 internal static extern void SetKeyParamDw(SafeKeyHandle hKey, int param, int dwValue);
开发者ID:peterdocter,项目名称:referencesource,代码行数:1,代码来源:utils.cs

示例8: _GetUserKey

 internal static extern int _GetUserKey(SafeProvHandle hProv, int keyNumber, ref SafeKeyHandle hKey);
开发者ID:peterdocter,项目名称:referencesource,代码行数:1,代码来源:utils.cs

示例9: GetMinimumKeySize

 private static int GetMinimumKeySize(SafeKeyHandle key)
 {
     var keyLengths = NCryptGetProperty<NCRYPT_SUPPORTED_LENGTHS>(key, KeyStoragePropertyIdentifiers.NCRYPT_LENGTHS_PROPERTY);
     return keyLengths.dwMinLength;
 }
开发者ID:jmelosegui,项目名称:pinvoke,代码行数:5,代码来源:NCryptFacts.cs

示例10: ExportCspBlob

 private static extern void ExportCspBlob(SafeKeyHandle hKey, int blobType, ObjectHandleOnStack retBlob);
开发者ID:peterdocter,项目名称:referencesource,代码行数:1,代码来源:utils.cs

示例11: CryptoAPITransform

        internal CryptoAPITransform(int algid, int cArgs, int[] rgArgIds, object[] rgArgValues, byte[] rgbKey, PaddingMode padding, CipherMode cipherChainingMode, int blockSize, int feedbackSize, bool useSalt, CryptoAPITransformMode encDecMode)
        {
            this.BlockSizeValue = blockSize;
            this.ModeValue = cipherChainingMode;
            this.PaddingValue = padding;
            this.encryptOrDecrypt = encDecMode;
            int[] destinationArray = new int[rgArgIds.Length];
            Array.Copy(rgArgIds, destinationArray, rgArgIds.Length);
            this._rgbKey = new byte[rgbKey.Length];
            Array.Copy(rgbKey, this._rgbKey, rgbKey.Length);
            object[] objArray = new object[rgArgValues.Length];
            for (int i = 0; i < rgArgValues.Length; i++)
            {
                if (rgArgValues[i] is byte[])
                {
                    byte[] sourceArray = (byte[]) rgArgValues[i];
                    byte[] buffer3 = new byte[sourceArray.Length];
                    Array.Copy(sourceArray, buffer3, sourceArray.Length);
                    objArray[i] = buffer3;
                }
                else if (rgArgValues[i] is int)
                {
                    objArray[i] = (int) rgArgValues[i];
                }
                else if (rgArgValues[i] is CipherMode)
                {
                    objArray[i] = (int) rgArgValues[i];
                }
            }
            this._safeProvHandle = Utils.AcquireProvHandle(new CspParameters(Utils.DefaultRsaProviderType));
            SafeKeyHandle invalidHandle = SafeKeyHandle.InvalidHandle;
            Utils._ImportBulkKey(this._safeProvHandle, algid, useSalt, this._rgbKey, ref invalidHandle);
            this._safeKeyHandle = invalidHandle;
            for (int j = 0; j < cArgs; j++)
            {
                int num;
                switch (rgArgIds[j])
                {
                    case 1:
                    {
                        this.IVValue = (byte[]) objArray[j];
                        byte[] iVValue = this.IVValue;
                        Utils.SetKeyParamRgb(this._safeKeyHandle, destinationArray[j], iVValue, iVValue.Length);
                        continue;
                    }
                    case 4:
                        this.ModeValue = (CipherMode) objArray[j];
                        num = (int) objArray[j];
                        break;

                    case 5:
                        num = (int) objArray[j];
                        break;

                    case 0x13:
                        num = (int) objArray[j];
                        break;

                    default:
                        throw new CryptographicException(Environment.GetResourceString("Cryptography_InvalidKeyParameter"), "_rgArgIds[i]");
                }
                Utils.SetKeyParamDw(this._safeKeyHandle, destinationArray[j], num);
            }
        }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:64,代码来源:CryptoAPITransform.cs

示例12: ImportParameters

 public override void ImportParameters(RSAParameters parameters)
 {
     if ((this._safeKeyHandle != null) && !this._safeKeyHandle.IsClosed)
     {
         this._safeKeyHandle.Dispose();
         this._safeKeyHandle = null;
     }
     RSACspObject cspObject = RSAStructToObject(parameters);
     this._safeKeyHandle = SafeKeyHandle.InvalidHandle;
     if (IsPublic(parameters))
     {
         Utils._ImportKey(Utils.StaticProvHandle, 0xa400, CspProviderFlags.NoFlags, cspObject, ref this._safeKeyHandle);
     }
     else
     {
         KeyContainerPermission permission = new KeyContainerPermission(KeyContainerPermissionFlags.NoFlags);
         KeyContainerPermissionAccessEntry accessEntry = new KeyContainerPermissionAccessEntry(this._parameters, KeyContainerPermissionFlags.Import);
         permission.AccessEntries.Add(accessEntry);
         permission.Demand();
         if (this._safeProvHandle == null)
         {
             this._safeProvHandle = Utils.CreateProvHandle(this._parameters, this._randomKeyContainer);
         }
         Utils._ImportKey(this._safeProvHandle, 0xa400, this._parameters.Flags, cspObject, ref this._safeKeyHandle);
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:26,代码来源:RSACryptoServiceProvider.cs

示例13: ImportCspBlobHelper

 internal static void ImportCspBlobHelper(CspAlgorithmType keyType, byte[] keyBlob, bool publicOnly, ref CspParameters parameters, bool randomKeyContainer, ref SafeProvHandle safeProvHandle, ref SafeKeyHandle safeKeyHandle)
 {
     if ((safeKeyHandle != null) && !safeKeyHandle.IsClosed)
     {
         safeKeyHandle.Dispose();
     }
     safeKeyHandle = SafeKeyHandle.InvalidHandle;
     if (publicOnly)
     {
         parameters.KeyNumber = _ImportCspBlob(keyBlob, (keyType == CspAlgorithmType.Dss) ? StaticDssProvHandle : StaticProvHandle, CspProviderFlags.NoFlags, ref safeKeyHandle);
     }
     else
     {
         KeyContainerPermission permission = new KeyContainerPermission(KeyContainerPermissionFlags.NoFlags);
         KeyContainerPermissionAccessEntry accessEntry = new KeyContainerPermissionAccessEntry(parameters, KeyContainerPermissionFlags.Import);
         permission.AccessEntries.Add(accessEntry);
         permission.Demand();
         if (safeProvHandle == null)
         {
             safeProvHandle = CreateProvHandle(parameters, randomKeyContainer);
         }
         parameters.KeyNumber = _ImportCspBlob(keyBlob, safeProvHandle, parameters.Flags, ref safeKeyHandle);
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:24,代码来源:Utils.cs

示例14: _GenerateKey

 internal static extern void _GenerateKey(SafeProvHandle hProv, int algid, CspProviderFlags flags, int keySize, ref SafeKeyHandle hKey);
开发者ID:peterdocter,项目名称:referencesource,代码行数:1,代码来源:utils.cs

示例15: SetKeyParamRgb

 internal static extern void SetKeyParamRgb(SafeKeyHandle hKey, int param, byte[] value, int cbValue);
开发者ID:peterdocter,项目名称:referencesource,代码行数:1,代码来源:utils.cs


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