售前咨询
技术支持
渠道合作

自动安装数字证书根证书

关于数字证书的 安装,很多人遇到很多不同的难题。其实在安装的过程中会有很多简单,下面,就给大家介绍关于怎样自动安装数字证书根证书:
[html] view plain copy

  1. <a target=“_blank” href=“http://www.cnblogs.com/jifeng/archive/2011/05/07/2040048.html”>http://www.cnblogs.com/jifeng/archive/2011/05/07/2040048.html</a>
[html] view plain copy

  1. <%@ page language=“java” import=“java.util.*” pageEncoding=“GBK”%>
  2. <%@ page import=“java.lang.*,java.io.*”%>
  3. <html>
  4.     <head>
  5.         <title>IE中自动安装数字证书测试</title>
  6.     </head>
  7.     <body>
  8.         IE中使用XEnroll.InstallPKCS7自动安装根数字证书
  9.         <br />
  10.         备注:这里测试的根证书采用Base64编码 X.509格式(CER)
  11.         <br />
  12. <%
  13. StringBuffer server_cert =new StringBuffer();
  14. try {
  15.     java.net.URL url =config.getServletContext().getResource(“/base64_root_comsys.cer”);
  16.     BufferedReader breader =new BufferedReader(new InputStreamReader(url.openStream()));
  17. }
  18. catch(Exception e)
  19. {
  20.     e.printStackTrace();
  21.     out.println(“<HTML><BODY><P>“);
  22.     out.println(“<h2>读取证书文件出错</h2> <br/>“);
  23.     out.println(e.toString());
  24.     out.println(“</P></BODY></HTML>“);
  25.     out.flush();
  26.     out.close();
  27. }
  28. String Agent = request.getHeader(“User-Agent”);
  29. StringTokenizer st = new StringTokenizer(Agent,”;”);
  30. st.nextToken();
  31. String userBrowser = st.nextToken();
  32. String userOS = st.nextToken();
  33. out.println(“你的操作系统为:”);
  34. out.println(userOS);
  35. String activexLib=“XEnroll”;
  36. //检查是否是Windows Vista,Windows 2008,Windows 7,在Vista,Windows 2008,Windows 7上,需要使用 CertEnroll.dll
  37. //Windows 2008 Server, IE7 User-Agent header: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2;…
  38. //Windows Vista, IE7 User-Agent header: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0;…
  39. //Windows 7,IE8 User-Agent header: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1;…
  40. if(userOS.indexOf(“Windows NT 6.0”)>-1 || userOS.indexOf(“Windows NT 6.1”)>-1 || userOS.indexOf(“Windows NT 5.2”)>-1){
  41.         activexLib=“CertEnroll”;
  42.     }
  43.     String sPKCS7=server_cert.toString();
  44.     sPKCS7=“—–BEGIN CERTIFICATE—–MIIDZzCCAk+gAwIBAgIJAJrhdPt6af7nMA0GCSqGSIb3DQEBBAUAMGoxFjAUBgNVBAoTDWNvbXN5cy5uZXQuY24xDTALBgNVBAsTBFVDSVQxHjAcBgNVBAMTFUNPTVNZUy5ORVQuQ04gUk9PVCBDQTEhMB8GCSqGSIb3DQEJARYSbGlhb2ppZmVuZ0AxNjMuY29tMB4XDTExMDQyMjAyMTkzMFoXDTE3MDQyMDAyMTkzMFowajEWMBQGA1UEChMNY29tc3lzLm5ldC5jbjENMAsGA1UECxMEVUNJVDEeMBwGA1UEAxMVQ09NU1lTLk5FVC5DTiBST09UIENBMSEwHwYJKoZIhvcNAQkBFhJsaWFvamlmZW5nQDE2My5jb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDnYB2tr8D3IcPND9tCh4c1GMnL15hdJ5oYJ12DpoaEbCciELkOmogaQ2IjVSLBCfHZKkX6X9hJqdCHH2oiGvNZyuN5mjfy+KWuebs7r9sqaTzJ6/e1vgSaiYox1DIO+oI59MH22jH3i8OMw2qbE3TqlLvVmZBflomVkGIOz95iJOzKOJwIUA3VhFYvI/Wlf4NzqfOL0zNNmoFUcD4BYVAqhVa570FFxEaGl8DvLaKUraKfho6zRHVc7MrjFrI6SlSRhe2hi/c24HrOpzoUPD46zztL/v6sSV37chsf6+V44WO4rCth0wEZzws8Hd6ch8NsUcMJjM8IOG2NMrn6x0CLAgMBAAGjEDAOMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEEBQADggEBAD4UIk7CVBwsK7DWg74eM2zwfU4bFm02BKMVFDVNwwTdjdcGSlxrNChbymHFuhG00USxy9/d4ApWxUX/y3MxmkXusENE2Rg6Wk92k6SCfbhIOXUrI+0YxXNAjInIcABsasOZAZ/ECuIuQbap5UyEHCiy0VJKRKKNCthE2dBbnTLaS1ierSuWubuyOMGDtQTCdjU7zYjwGLSLNXkUGNfG+t5XkltXRNFxUgkVh6q2sHxo76I2taya4KQp2SM6W4t8tdJXzBvdI1me5bT7sWDu4fYwsTnjwQACXrb6PKi86jq3YxP3DV/t+Beq87NP2mJg+0Ind8RNTenM714R7VtFrz8=—–END CERTIFICATE—–“;
  45. %>
  46.         <% if(activexLib.equals(“XEnroll”)){ %>
  47.         <object id=“XEnroll” classid=“clsid:127698e4-e730-4e5c-a2b1-21490a70c8a1” codebase=“xenroll.dll”>
  48.         </object>
  49.         <SCRIPT language=“VBSCRIPT”>
  50.             ON ERROR resume next
  51.             sPKCS7=“—–BEGIN CERTIFICATE—–MIIDZzCCAk+gAwIBAgIJAJrhdPt6af7nMA0GCSqGSIb3DQEBBAUAMGoxFjAUBgNVBAoTDWNvbXN5cy5uZXQuY24xDTALBgNVBAsTBFVDSVQxHjAcBgNVBAMTFUNPTVNZUy5ORVQuQ04gUk9PVCBDQTEhMB8GCSqGSIb3DQEJARYSbGlhb2ppZmVuZ0AxNjMuY29tMB4XDTExMDQyMjAyMTkzMFoXDTE3MDQyMDAyMTkzMFowajEWMBQGA1UEChMNY29tc3lzLm5ldC5jbjENMAsGA1UECxMEVUNJVDEeMBwGA1UEAxMVQ09NU1lTLk5FVC5DTiBST09UIENBMSEwHwYJKoZIhvcNAQkBFhJsaWFvamlmZW5nQDE2My5jb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDnYB2tr8D3IcPND9tCh4c1GMnL15hdJ5oYJ12DpoaEbCciELkOmogaQ2IjVSLBCfHZKkX6X9hJqdCHH2oiGvNZyuN5mjfy+KWuebs7r9sqaTzJ6/e1vgSaiYox1DIO+oI59MH22jH3i8OMw2qbE3TqlLvVmZBflomVkGIOz95iJOzKOJwIUA3VhFYvI/Wlf4NzqfOL0zNNmoFUcD4BYVAqhVa570FFxEaGl8DvLaKUraKfho6zRHVc7MrjFrI6SlSRhe2hi/c24HrOpzoUPD46zztL/v6sSV37chsf6+V44WO4rCth0wEZzws8Hd6ch8NsUcMJjM8IOG2NMrn6x0CLAgMBAAGjEDAOMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEEBQADggEBAD4UIk7CVBwsK7DWg74eM2zwfU4bFm02BKMVFDVNwwTdjdcGSlxrNChbymHFuhG00USxy9/d4ApWxUX/y3MxmkXusENE2Rg6Wk92k6SCfbhIOXUrI+0YxXNAjInIcABsasOZAZ/ECuIuQbap5UyEHCiy0VJKRKKNCthE2dBbnTLaS1ierSuWubuyOMGDtQTCdjU7zYjwGLSLNXkUGNfG+t5XkltXRNFxUgkVh6q2sHxo76I2taya4KQp2SM6W4t8tdJXzBvdI1me5bT7sWDu4fYwsTnjwQACXrb6PKi86jq3YxP3DV/t+Beq87NP2mJg+0Ind8RNTenM714R7VtFrz8=—–END CERTIFICATE—–“
  52.             XEnroll.InstallPKCS7 sPKCS7
  53.             //XEnroll.InstallPKCS7用于安装根证书。
  54.             XEnroll.InstallPKCS7 sPKCS7
  55.              if err.Number <> 0 then
  56.                  if err.number = -2146885628 then
  57.                      MsgBox “Keyset does not exist”
  58.                  else
  59.                      MsgBox “证书下载时出错,错误号=”&err.description
  60.                  end if
  61.             else
  62.                 MsgBox “证书已成功装入”
  63.             end if
  64.     </script>
  65.         <% }
  66. else {%>
  67. <!–
  68.         //方法来源://http://blogs.msdn.com/alejacma/archive/2009/01/28/how-to-create-a-certificate-request-with-certenroll-javascript.aspx
  69.         //Vista下由于暂时没有测试环境,方法尚待验证
  70. >
  71.         <object id=“objCertEnrollClassFactory” classid=“clsid:884e2049-217d-11da-b2a4-000e7bbb2b09”></object>
  72.         <script language=“javascript”>
  73.           function InstallCert(){
  74.                 document.write(“<br>Installing certificate…”);
  75.                 try {
  76.                     // Variables
  77.                     var objEnroll = objCertEnrollClassFactory.CreateObject(“X509Enrollment.CX509Enrollment”)
  78.                     var sPKCS7 = “<%= sPKCS7 %>”
  79.                     objEnroll.Initialize(1); // ContextUser
  80.                     objEnroll.InstallResponse(0, sPKCS7, 6, “”);
  81.                     // AllowNone = 0XCN_CRYPT_STRING_BASE64_ANY = 6
  82.                 }catch (err)
  83.                 {
  84.                     document.write(“<br>” + err.description);
  85.                     return false;
  86.                  }
  87.                 return true;
  88.             }
  89.         InstallCert();
  90. </script>
  91.         <% } %>
  92.         <%/*
  93. out.println(“用下载方式下载p12格式的文件下载后安装”);
  94. ClassLoader cl = this.getClass().getClassLoader();
  95. try
  96. {
  97. InputStream is = cl.getResourceAsStream(“liangchuan.p12”);
  98.  //response.setContentType(“application/x-x509-ca-cert”);
  99.  response.setContentType(“application/x-pkcs12”);
  100. response.addHeader(“Content-Disposition”, “attachment; filename=liangchuan.p12″);
  101.  OutputStream os = response.getOutputStream();
  102. //InputStream is = new FileInputStream(fileName);
  103.  while (is.available() > 0)
  104. {
  105. char c = (char) is.read();
  106.  os.write(c);    }
  107. os.flush();
  108. is.close(); }
  109. catch (Exception e) {
  110. out.println(“<HTML><BODY><P>“);
  111. out.println(“<h2>下载证书文件出错</h2> <br/>“);
  112. out.println(e.toString());
  113. out.println(“</P></BODY></HTML>“);
  114. out.flush();
  115. out.close(); }*/%>
  116.     </body>
  117. </html>相关搜索

    社保数字证书怎么安装
    手机安装数字证书
    公安数字证书怎么安装
    微信数字证书怎么安装
    数字证书是什么
    国税数字证书怎么安装
    工商数字证书怎么安装
    报税数字证书怎么安装

上一篇:

下一篇:

相关新闻