zoukankan      html  css  js  c++  java
  • C#中用SslEmptyCache系统API来清除SSL状态

    如果需要编程实现IE选项中清除SSL状态的功能,可用SslEmptyCache函数,SslEmptyCache函数定义在Schannel.dll中,采用动态链接即可。

    代码如下:

    using System;
    using System.Runtime.InteropServices;

    namespace Demo
    {
        
    public class Ssl
        {
            [DllImport(
    "kernel32.dll")]
            
    internal static extern IntPtr LoadLibrary(String dllname);

            [DllImport(
    "kernel32.dll")]
            
    internal static extern IntPtr GetProcAddress(IntPtr hModule, String procname);

            
    internal delegate bool SslEmptyCacheHelper(IntPtr targetName, int flags);

            
    /// <summary>
            
    /// UNICODE版
            
    /// </summary>
            
    /// <returns></returns>
            public bool SslEmptyCacheW()
            {
                IntPtr schannel 
    = LoadLibrary("Schannel.dll");
                IntPtr procaddr 
    = GetProcAddress(schannel, "SslEmptyCacheW");
                SslEmptyCacheHelper helper 
    = (SslEmptyCacheHelper)Marshal.GetDelegateForFunctionPointer(procaddr, typeof(SslEmptyCacheHelper));
                
    return helper(IntPtr.Zero, 0);
            }

            
    /// <summary>
            
    /// ANSI版
            
    /// </summary>
            
    /// <returns></returns>
            public bool SslEmptyCacheA()
            {
                IntPtr schannel 
    = LoadLibrary("Schannel.dll");
                IntPtr procaddr 
    = GetProcAddress(schannel, "SslEmptyCacheA");
                SslEmptyCacheHelper helper 
    = (SslEmptyCacheHelper)Marshal.GetDelegateForFunctionPointer(procaddr, typeof(SslEmptyCacheHelper));
                
    return helper(IntPtr.Zero, 0);
            }
        }

    }

    参考资料:

    1、SslEmptyCache Function

    2、.NET 2.0 中 GetDelegateForFunctionPointer 函数实现原理浅析 [草稿]

  • 相关阅读:
    Referenced file contains errors (http://www.springframework.org/...解决
    Echarts的提示(Tooltip)显示额外内容
    后端&前端零碎知识点和注意问题
    RocketMQ 4.5.1 双主双从异步复制环境搭建
    个人时间管理
    Windows系统封装教程
    你要如何衡量你的人生
    如何让你爱的人爱上你
    舔狗不会永远舔你的爱答不理和高冷
    关于小孩的教育问题
  • 原文地址:https://www.cnblogs.com/hhh/p/1269302.html
Copyright © 2011-2022 走看看