我的网站需要这样一个功能,用户在注册后自动下载一个数字证书,证书中包括用户的公司、地址、email等数字证书常用属性。我查阅过相关代码,很多资料都给出这个网址中的函数:http://blog.csdn.net/onlyzhangqin/archive/2008/03/21/2203118.aspx哪位大侠能帮忙解释一下这个函数中的每个参数的含义以及这个函数的用法,或者有更好的方法解决自动申请数字证书的问题,小弟在这里先谢过了。
另外我的证书服务器是按照这个网址的方案配置的 http://www.cnblogs.com/chnking/archive/2008/08/18/1270063.html 我的服务器应该怎么配置。

解决方案 »

  1.   

    我是楼主,这个问题我知道,我只作测试,根证书服务器我都是自己配置的。现在能够通过微软提供的asp页面自己手动申请证书,想用代码实现自动生成,大家有什么办法吗?
      

  2.   

    代码中行不行我不知道,你肯定是可以用command来执行certmgr.exe 和 makecert.exe来实现的.certmgr.exe 和 makecert.exe可以在.NET SDK里面可以找到.
    下面是我的一个项目中创建测试certificate的command.echo off
    setlocal
    echo ************
    echo cert setup starting
    echo ************cd Toolcall :setscriptvariables %1
    IF NOT DEFINED SUPPORTED_MODE call :displayusage
    IF DEFINED SUPPORTED_MODE call :cleancerts
    IF DEFINED SETUP_SERVICE call :setupservice
    GOTO end:cleancerts
    REM cleans up certs from previous runs.
    echo ****************
    echo Cleanup starting
    echo ****************echo -------------------------
    echo del client certs
    echo -------------------------
    certmgr.exe -del -r CurrentUser -s TrustedPeople -c -n %SERVER_NAME%echo -------------------------
    echo del service certs
    echo -------------------------
    certmgr.exe -put -r LocalMachine -s My -c -n %SERVER_NAME% ..\monitor.cer
    IF %ERRORLEVEL% EQU 0 (
       DEL computer.cer
       echo ****************
       echo "You have a certificate with a Subject name matching your Machine name: %SERVER_NAME%"
       echo "If this certificate is from a cross machine run of WCF samples press any key to delete it."
       echo "Otherwise press Ctrl + C to abort this script."
       pause
       certmgr.exe -del -r LocalMachine -s My -c -n %SERVER_NAME%
    ):cleanupcompleted
    echo *****************
    echo Cleanup completed
    echo *****************GOTO :EOF:setupserviceecho ************
    echo Server cert setup starting
    echo %SERVER_NAME%
    echo ************
    echo making server cert
    echo ************makecert.exe -sr LocalMachine -ss MY -a sha1 -n CN=%SERVER_NAME% -sky exchange -peIF DEFINED EXPORT_SERVICE (
        echo ************
        echo exporting service cert to monitor.cer
        echo ************
        certmgr.exe -put -r LocalMachine -s My -c -n %SERVER_NAME% ..\monitor.cer
    ) ELSE (
        echo ************
        echo copying server cert to client's CurrentUser store
        echo ************
        certmgr.exe -add -r LocalMachine -s My -c -n %SERVER_NAME% -r CurrentUser -s TrustedPeople
    )
    GOTO :EOF:setscriptvariables
    REM Parses the input to determine if we are setting this up for a single machine, client, or server
    REM sets the appropriate name variables
    SET SUPPORTED_MODE=1
    SET SETUP_SERVICE=1
    SET EXPORT_SERVICE=1
    SET SERVER_NAME=%1
    IF [%1]==[] SET SERVER_NAME=MonitorServer
    ECHO %SERVER_NAME%GOTO :EOF
    :displayusage
    ECHO Correct usage:
    ECHO     Service Machine - Setup.bat MonitorServer
    :endpause