Example #1
0
 private CryptApi()
 {
     const string IntelDefaultProvider = "Intel Hardware Cryptographic Service Provider";
        handle = new SafeCryptHandle();
        if (NativeMethods.CryptAcquireContext(out handle, null,
     IntelDefaultProvider, NativeMethods.PROV_INTEL_SEC, 0))
        {
     return;
        }
        else if (NativeMethods.CryptAcquireContext(out handle, null,
     null, NativeMethods.PROV_RSA_FULL, 0))
        {
     return;
        }
        else if (Marshal.GetLastWin32Error() == NativeMethods.NTE_BAD_KEYSET)
        {
     if (NativeMethods.CryptAcquireContext(out handle, null, null,
      NativeMethods.PROV_RSA_FULL, NativeMethods.CRYPT_NEWKEYSET))
     {
      return;
     }
        }
        throw new NotSupportedException("Unable to acquire a cryptographic service provider.");
 }
Example #2
0
         public static extern bool CryptAcquireContext(out SafeCryptHandle phProv,
 string pszContainer, string pszProvider, uint dwProvType, uint dwFlags);
Example #3
0
         public static extern bool CryptGenRandom(SafeCryptHandle hProv, uint dwLen,
 byte[] pbBuffer);
Example #4
0
 private void Dispose(bool disposing)
 {
     if (handle == null)
     return;
        if (disposing)
     handle.Close();
        handle = null;
 }