void GenerateKeys()
        {
            // generate the key container to put the key in
            if (!CryptAcquireContext(out keyContainer,
                                     keyContainerName,
                                     null,
                                     ProviderType.RsaSecureChannel,
                                     ContextFlags.NewKeySet | ContextFlags.Silent))
            {
                int error = Marshal.GetLastWin32Error();
                Utility.CloseInvalidOutSafeHandle(keyContainer);
                keyContainer = null;
                PeerExceptionHelper.ThrowInvalidOperation_PeerCertGenFailure(new Win32Exception(error));
            }

            // generate the key
            if (!CryptGenKey(keyContainer,
                             AlgorithmType.KeyExchange,
                             KeyFlags.Exportable2k,
                             out key))
            {
                int error = Marshal.GetLastWin32Error();
                Utility.CloseInvalidOutSafeHandle(key);
                key = null;
                PeerExceptionHelper.ThrowInvalidOperation_PeerCertGenFailure(new Win32Exception(error));
            }
        }
 extern static bool CertSetCertificateContextProperty(
                                             CertificateHandle context,
                                             int propId,
                                             int flags,
                                             KeyHandle pv);
        void GenerateKeys()
        {
            // generate the key container to put the key in
            if (!CryptAcquireContext(out keyContainer,
                                        keyContainerName,
                                        null,
                                        ProviderType.RsaSecureChannel,
                                        ContextFlags.NewKeySet | ContextFlags.Silent))
            {
                int error = Marshal.GetLastWin32Error();
                Utility.CloseInvalidOutSafeHandle(keyContainer);
                keyContainer = null;
                PeerExceptionHelper.ThrowInvalidOperation_PeerCertGenFailure(new Win32Exception(error));
            }

            // generate the key
            if (!CryptGenKey(keyContainer,
                                AlgorithmType.KeyExchange,
                                KeyFlags.Exportable2k,
                                out key))
            {
                int error = Marshal.GetLastWin32Error();
                Utility.CloseInvalidOutSafeHandle(key);
                key = null;
                PeerExceptionHelper.ThrowInvalidOperation_PeerCertGenFailure(new Win32Exception(error));
            }
        }
 extern static bool CertSetCertificateContextProperty(
     CertificateHandle context,
     int propId,
     int flags,
     KeyHandle pv);
 extern static bool CryptGenKey(
     KeyContainerHandle hProv,
     AlgorithmType algId,
     KeyFlags dwFlags,
     [Out] out KeyHandle phKey);
 private static extern bool CryptGenKey(KeyContainerHandle hProv, AlgorithmType algId, KeyFlags dwFlags, out KeyHandle phKey);
 private static extern bool CryptGenKey(KeyContainerHandle hProv, AlgorithmType algId, KeyFlags dwFlags, out KeyHandle phKey);