怎样制作数字签名

来源:互联网 发布:jsp import java 编辑:程序博客网 时间:2024/06/10 03:54

怎样制作数字签名

1、 获得软件发行证书(测试)

一、找到或下载signcode.exe、makecert.exe和cert2spc.exe这三个程序,如果装了VS.NET的话,可以在其目录下找到,或者去微软网上下载也可以的。

二、:创建用于数字签名的公钥和私钥对,并将其存储在证书文件中。

输入makecert -sk lyl -n "CN=johnlya" c:/lyl.cer。

就会在你的C:生成lyl.cer文件。

说明:参数-n指定主题的证书名称。此名称必须符合 X.500 标准。最简单的方法是在双引号中指定此名称,并加上前缀 CN=;例如,"CN=myName"。注意这里的CN必须大写。-sk指定主题的密钥容器位置,该位置包含私钥。如果密钥容器不存在,系统将创建一个。输入makecert -?可以查看其他参数的用法。

三:创建发行者证书 (SPC)。

注意,发行者证书测试工具通过一个或多个 X.509 证书创建发行者证书 (SPC)。Cert2spc.exe 仅用于测试目的。可以从证书颁发机构(如 VeriSign 或 Thawte)获得有效的 SPC。

输入命令:cert2spc c:/lyl.cer c:/lyl.spc,在C:盘生成证书文件。至此,你已经拥有了仅用于测试的软件证书。其实,我们开发的程序或ActiveX控件只要仅用于企业内部,完全可以用这种办法作数字签名,使你的控件可以在浏览器里自动下载,而不必去专门的证书办法机构获得证书。

2、 创建CAB文件

CAB文件是一种WINDOWS的标准压缩格式文件,在网页上发布ActiveX的时候经常使用该压缩格式对文件进行包装,目的是使文件便于在Internet上传输。创建CAB文件的方法有很多,可以压缩工具CABARC.EXE。

也可不使用 CAB 文件而直接签名 DLL 和 OCX。CAB 文件的优势在于压缩,而且如果与 INF 文件一起使用,它可将所有必要的代码绑定在一起。

INF文件如下:

   ; ========================= johnlya.inf ========================

   [version]
   ; version signature (same for both NT and Win95) do not remove
   signature="$johnlya$"
   AdvancedINF=3.0

   [Add.Code]
   johnlya.ocx= johnlya.ocx
   PEGRP32C.DLL = PEGRP32C.DLL
   ; These are the necessary supporting DLLs for MFC 4.2 ActiveX Controls
   mfc42.dll=mfc42.dll
   msvcrt.dll=msvcrt.dll
   olepro32.dll=olepro32.dll
 
   ; thiscab is a keyword which, in this case, means that johnlya.ocx
   ; can be found in the same .cab file as this .inf file
   ; file-win32-x86 is an x86 platform specific identifier
   ; See the ActiveX SDK - ActiveX Controls - Internet Component Download -
   ; Packaging component code for automatic download
 ; needed DLL
  [PEGRP32C.DLL]
  file-win32-x86=thiscab
  FileVersion=5,0,0,0
  DestDir=11
  RegisterServer=yes


   [johnlya.ocx]
   file-win32-x86=thiscab
   ; *** add your controls CLSID here ***
   clsid={D63A6E56-E666-49F2-99B5-D0EFE1B7647F}
   ; Add your ocx's file version here.
   FileVersion=3,0,2,1
   RegisterServer=yes
  
  
   ; dependent DLLs
   [msvcrt.dll]
   ; This is an example of conditional hook. The hook only gets processed
   ; if msvcrt.dll of the specified version is absent on client machine.
   FileVersion=6,0,8168,0
   hook=mfc42installer

   [mfc42.dll]
   FileVersion=6,0,8168,0
   hook=mfc42installer

   [olepro32.dll]
   FileVersion=5,0,4261,0
   hook=mfc42installer
  
    [mfc42installer]
   file-win32-x86=VALUE=http://activex.microsoft.com/controls/vc/mfc42.cab
   ; If dependent DLLs are packaged directly into the above cabinet file
   ; along with an .inf file, specify that .inf file to run as follows:
   ;InfFile=mfc42.inf
   ; The mfc42.cab file actually contains a self extracting executable.
   ; In this case we specify a run= command.
   run=%EXTRACT_DIR%/mfc42.exe

   ; ====================== end of johnlya.inf =====================

然后在命令行模式下输入:

cabarc -s 6144 n johnlya.cab PEGRP32C.DLL johnlya.ocx johnlya.inf

3、 签署文件

在上面打开的dos窗口里,输入如下命令:

signcode /spc c:/lyl.spc /k johnlya -t http://timestamp.verisign.com/scripts/timstamp.dll c:/lyl.cab

至此,已经对成功对lyl.cab文件签名。可以查看文件的属性,查看数字签名。


4、注意一点:对于WINXP需要将Internet/工具/选项/高级里将允许和安装未授权的数字签名选项打上勾!

原创粉丝点击