/// <summary> /// This method helps Acquire the default CSP and avoids the need for static SafeProvHandle /// in CapiHelper class /// </summary> private SafeProvHandle AcquireSafeProviderHandle(CspParameters cspParams) { SafeProvHandle safeProvHandleTemp; CapiHelper.AcquireCsp(cspParams, out safeProvHandleTemp); return(safeProvHandleTemp); }
/// <summary> /// This method helps Acquire the default CSP and avoids the need for static SafeProvHandle /// in CapiHelper class /// </summary> private SafeProvHandle AcquireSafeProviderHandle() { SafeProvHandle safeProvHandle; CapiHelper.AcquireCsp(new CspParameters(CapiHelper.DefaultRsaProviderType), out safeProvHandle); return(safeProvHandle); }
///// <summary> ///// Шаг хеширования. ///// </summary> ///// ///// <param name="hashAlgorithm">HashAlgorithmName</param> ///// <param name="data">Массив с хешируемыми данними.</param> ///// <param name="offset">Начало хешируемого блока в массиве.</param> ///// <param name="count">Размер хешируемого блока.</param> ///// ///// <exception cref="CryptographicException">При ошибках на native ///// уровне.</exception> //[SecurityCritical] //protected override byte[] HashData(byte[] data, int offset, int count, HashAlgorithmName hashAlgorithm) //{ // CapiHelper.CryptHashData(this.SafeHashHandle, data, count, 0); // return CapiHelper.EndHash(this.SafeHashHandle); //} /// <summary> /// This method helps Acquire the default CSP and avoids the need for static SafeProvHandle /// in CapiHelper class /// </summary> private SafeProvHandle AcquireSafeProviderHandle() { SafeProvHandle safeProvHandleTemp; CapiHelper.AcquireCsp(new CspParameters(GostConstants.PROV_GOST_2012_256), out safeProvHandleTemp); return(safeProvHandleTemp); }
/// <summary> /// Импортирует (дешифрует) секретный ключ. /// </summary> /// <param name="wrapped">Зашифрованный секретный ключ.</param> /// <param name="method">Алгоритм экспорта ключа.</param> public override SymmetricAlgorithm Unwrap(byte[] wrapped, GostKeyWrapMethod method) { GostWrappedKeyObject gwk = new GostWrappedKeyObject(); gwk.SetByXmlWrappedKey(wrapped); int calg = GostConstants.CALG_SIMPLE_EXPORT; if (method == GostKeyWrapMethod.CryptoProKeyWrap) { calg = GostConstants.CALG_PRO_EXPORT; } else if (method == GostKeyWrapMethod.CryptoPro12KeyWrap) { calg = GostConstants.CALG_PRO12_EXPORT; } else if (method != GostKeyWrapMethod.GostKeyWrap) { throw new ArgumentOutOfRangeException("method"); } SymmetricAlgorithm ret = null; // Сохраняем состояние algid GOST12147 using (SafeKeyHandle hExpKey = CapiHelper.DuplicateKey(SafeKeyHandle.DangerousGetHandle())) { CapiHelper.SetKeyParamDw(hExpKey, GostConstants.KP_ALGID, calg); SafeKeyHandle simmKey = SafeKeyHandle.InvalidHandle; CapiHelper.AcquireCsp(_parameters, out SafeProvHandle hProv); CapiHelper.ImportSessionWrappedKey( hProv, CspProviderFlags.NoFlags, gwk, hExpKey, ref simmKey); ret = new Gost28147CryptoServiceProvider(simmKey, hProv); } return(ret); }
private static SafeProvHandle AcquireSafeProviderHandle(CspParameters?cspParams) { cspParams ??= new CspParameters(CapiHelper.DefaultRsaProviderType); CapiHelper.AcquireCsp(cspParams, out SafeProvHandle safeProvHandle); return(safeProvHandle); }
private static SafeProvHandle AcquireSafeProviderHandle(CspParameters cspParams) { if (cspParams == null) { cspParams = new CspParameters(CapiHelper.DefaultRsaProviderType); } SafeProvHandle safeProvHandle = null; CapiHelper.AcquireCsp(cspParams, out safeProvHandle); return(safeProvHandle); }
/// <summary> /// This method helps Acquire the default CSP and avoids the need for static SafeProvHandle /// in CapiHelper class /// </summary> /// <param name="safeProvHandle"> SafeProvHandle. Intialized if successful</param> /// <returns>does not return. AcquireCSP throw exception</returns> private void AcquireSafeProviderHandle(ref SafeProvHandle safeProvHandle) { CapiHelper.AcquireCsp(new CspParameters(CapiHelper.DefaultRsaProviderType), ref safeProvHandle); }