第1步 下载签名工具 Step 1: Download Signing Tools

如果您还没有签名工具,请到SUN公司网站免费下载:http://java.sun.com/j2se/,推荐下载JDK1.4.2或以上版本,支持Solaris SPARC/x86, Linux86 和 Windows 操作系统。
If you have not already done so, download the Java 2 Software
Development Kit (SDK). The latest version is available free of charge
for the Solaris SPARC/x86, Linux86, and Microsoft Windows platforms
from http://java.sun.com/j2se/.

您将使用签名工具中的 keytool, jar, jarsigner 来申请代码签名证书和数字签名您的代码。 
You will be using the keytool, jar, and jarsigner to apply for your Code Signing Certificate and sign your code.

第2步 申请签名证书 Step 2: Enrollment (如果您没有证书,请联系易维信(EVTrust)申请)

(1) 生成私钥和公钥对(Keystore) Create a Keystore

使用以下命令生成私钥和公钥对: 
To generate a public/private key pair, enter the following
command, specifying a name for your keystore and an alias as well.

c:\jdk1.5\bin\keytool -genkey -keyalg rsa -keystore <keystore_filename> -alias <alias_name>

Keytool 会提示您输入私钥密码、您的姓名(Your
name,填单位网址)、您的部门名称、单位名称、所在城市、所在省份和国家缩写(中国填:CN,其他国家填其缩写),单位名称一定要与证明文件上的名称
一致,部门名称(OU)可以不填。除国家缩写必须填CN外,其余都可以是英文或中文。请一定要保存好您的私钥和私钥密码。我们不会要求您提供私钥文件!
Keytool prompts you to enter a password for your keystore,
your name, organization, and address. The public/private key pair
generated by keytool is saved to your keystore and will be used to sign
Java Applets and applications. This key is never sent to GlobalSign and
is required to sign code. GlobalSign encourages you to make a copy of
the public/private key pair and store it in a safe deposit box or other
secure location. If the key is lost or stolen, contact GlobalSign
immediately to have it revoked.

(2) 生成证书请求文件(CSR) Generate a CSR

请使用如下命令生成证书请求文件(CSR): 
You need to generate a Certificate Signing Request (CSR) for
the enrollment process, the following command requests Keytool to create
a CSR for the key pair in the keystore:

c:\jdk1.5\bin\keytool –certreq –file certreq.csr –keystore <keystore_filename> -alias <alias_name>

请把生成的certreq.csr 文件复制和粘贴到GlobalSign证书在线申请页面的CSR文本框中,或直接发给维瑞客服,请等待1-2个工作日后颁发证书。
Copy the contents of the CSR and paste them directly into the
维瑞信 enrollment form. Open the file in a text editor that does not add
extra characters (Notepad or Vi are recommended).

第3步 使用代码签名证书 Step 3: Begin Using

(1) 导入签名证书 Import GlobalSign Codesigning Certificate

一旦GlobalSign验证了您的真实身份,将会颁发证书给您。您需要到GlobalSign网站下载您的证书,请选择
PKCS #7 格式证书(PKCS #7 Certificate Chain),此证书格式含有您的证书和根证书链,Keytool要求此格式证书
,请把证书保存到您的电脑中。
Once GlobalSign has verified your identity, we will send a
confirmation e-mail with your Sun Java Code Signing Certificate
attached. Upon receipt, the attached Code Signing Certificate is saved
to a file on your computer. A Code Signing Certificate is a "trust path"
or "chain" back to the GlobalSign root certificate. This "trust path"
allows your code to be validated on any standard JRE without installing
any additional files.

请使用如下命令导入您的证书到keystore 中,这里假设您的证书名称为:cert.cer,请同时指明详细路径,一旦成功导入证书,请及时备份您的keystore文件: 
To import your Sun Java Signing Code Signing Certificate into
your keystore, enter the following code with the path correct name for
your file (for example, “cert.cer”).

c:\jdk1.5\bin\keytool -import –trustcacerts –keystore <keystore_filename> -alias <alias_name> -file cert.cer

(2) 把Applet代码打包成JAR文件 Bundle Applet into a JAR File

请使用jar 把您的Java代码打包成JAR文件,此JAR文件包含了当前目录及其子目录的所有Applet文件: 
Use jar to bundle your Applets or applications as a JAR file.
This string creates a JAR file C:\TestApplet.jar. The JAR file contains
all the files under the current directory and its sub-directories.

c:\jdk1.5\bin\jar cvf C:\TestApplet.jar

运行后, Jar会显示: Jar responds:

added manifest 
adding: TestApplet.class (in = 94208) (out= 20103)(deflated 78%) 
adding: TestHelper.class (in = 16384) (out= 779)(deflated 95%)

(3) 数字签名Applet Sign Your Applet

使用jarsigner签名您的JAR文件,最后的参数Mycert为Keystore中签名证书的别名:
Use jarsigner to sign the JAR file with the private key you saved in your keystore.

c:\jdk1.5\bin\jarsigner C:\TestApplet.jar MyCert

(a) 会提示您输入私钥密码,请使用您在第1步设置的密码;
At the prompt, enter the password to your keystore.

(b) 请输入.jar文件的完整路径和文件名,MyCert 就是您在生成私钥和CSR时使用的别名<alias_name>;
In the command syntax, TestApplet represents the name and
location of your JAR file. MyCert must specify the same value that you
used when generating the key pair and certificate signing request (CSR).

(c) Jarsigner 会生成您的代码摘要(Hash),并把此摘要和您的签名证书添加到JAR文件中。
Jarsigner hashes your Applet or application and stores the
hash in the JAR file with a copy of your Code Signing Certificate.

如果您已经有了从其他电脑上备份的Keystore文件(如:wotonecs.jks),则可以使用如下命令来签名JAR文件,最后的参数wotonecs为Keystore中签名证书的别名:

c:\jdk1.5\bin\jarsigner -keystore wotonecs.jks C:\TestApplet.jar wotonecs

(d) 使用以下命令验证已经签名的JAR文件 Verify the output of your signed JAR file.

c:\jdk1.5\bin\jarsigner -verify -verbose -certs c:\TestApplet.jar

一旦成功签名,就可以把已经签名的JAR文件放到网上供用户下载了,用户端的Java系统会显示您的签名证书信息,如果已经签名的文件被篡改或损坏,则系统会提醒用户并拒绝安装。 
When the signed JAR file is downloaded, the Java Runtime
Environment will display your certificate to the user. If the file is
tampered with in any way after it has been signed, the user will be
notified and given the option to refuse installation.

Java代码签名证书申请和使用指南的更多相关文章

  1. Thawte 企业版代码签名证书

      Thawte企业版代码签名证书 ,严格验证企业身份,如果您是个人开放者,请申请Thawte 个人代码签名证书.Thawte企业代码签名证书 可帮助程序开发者使用微软代码签名工具(Microsoft ...

  2. Adobe AIR 代码签名证书使用指南

    Symantec,Thawte,GlobalSign 签发的代码签名证书都可以签名AIR文件.如果您还没有代码签名证书,请联系易维信(EVTrust)购买Adobe AIR 代码签名证书. 1.签名工 ...

  3. Win10内核驱动强制签名,申请沃通 EV代码签名证书

    2016年7月,微软在MSDN宣布从Windows 10的1607版本开始,强制要求所有新的Win10 内核驱动程序,必须获得Windows硬件开发者中心仪表盘门户的数字签名才能在系统中运行.这项政策 ...

  4. 使用Symantec代码签名证书对代码进行签名的 5 个理由

    借助 Symantec Code Signing,在更多平台上将您的代码提供给更多客户,我们总结了5大理由告诉软件开发者在发布自己的软件时一定要购买Symantec 代码签名证书签名即将发布的软件. ...

  5. Windows 硬件开发人员怎样选择代码签名证书类型

    在建立 Windows 开发人员中心硬件仪表板帐户之前,你需要获取代码签名证书以保护数字信息的安全.此证书是用于建立你的公司对你所提交代码的所有权的接受标准.它让你可以用数字形式签署 PE 二进制文件 ...

  6. 沃通SSL证书、代码签名证书应用于机器人安全防护

    近两年,扫地机器人.智能音箱等消费级机器人产品逐渐走入大众生活的中.随着人工智能技术的迅猛发展,预计2023年全球消费级机器人市场规模将达到150亿美元.然而,产业的迅猛发展却伴随着安全防护的缺失,安 ...

  7. 使用XCA(X Certificate and key management)可视化项目经理SSL 凭证(4)--凭借自身的凭证管理中心的定义(Certificate Authority)签名证书申请

    随着XCA(X Certificate and key management)可视化项目经理SSL 证书系列文章(2)和(3)中.我们学习了怎样用XCA(X Certificate and key m ...

  8. MQTT研究之EMQ:【JAVA代码构建X509证书】

    这篇帖子,不会过多解释X509证书的基础理论知识,也不会介绍太多SSL/TLS的基本信息,重点介绍如何用java实现SSL协议需要的X509规范的证书. 之前的博文,介绍过用openssl创建证书,并 ...

  9. MDM证书申请的流程

    MDM证书申请的流程 整个流程分为两部分:vendor,customer. 一.Vendor 1.成为一个 MDM Vendor 1) 首先你需要拥有一个 Apple Enterprise accou ...

随机推荐

  1. TSQL--自增键和索引对表的插入效率测试

    问题描述:数据库操作中,需要对表频繁插入数据,但发现插入效率不高. 解决思路:将数据缓存在服务器上,积攒到一定条数后批处理发送到数据库,在插入时考虑并发和索引对插入效率的影响. 测试结果:      ...

  2. 使用Base64进行string的加密和解密

    //字符串转bytes var ebytes = System.Text.Encoding.Default.GetBytes(keyWord); //bytes进行base64加密 var strBa ...

  3. Android 如何保存资源 Id 数组在 res/values/arrays.xml 里

    <resources> <!-- Tracks Information --> <array name="music_ids"> <ite ...

  4. ASP.NET Core根据环境切换NLog配置

    1.新建NLog配置文件,名称分别为nlog.config和nlog.debug.config <?xml version="1.0"?> <nlog xmlns ...

  5. 牛客OI赛制测试赛1 题解

    A 斐波那契 数竞生:这不是送分的常识吗? 这里引入一个叫卡西尼恒等式的玩意. 公式表达就是 设$fib[i]$为斐波那契数列的第$i$项$(i>0,i \in N_+)$ 则有 $fib[i+ ...

  6. sonarLint和sonarQube

    在线安装和离线装sonarLint https://blog.csdn.net/limm33/article/details/51166840 下载指定版本的sonarLint https://bin ...

  7. Cannot sending data from mongodb into elasticsearch using logstash

    Question: Hi all, i have an issue when i try to get data from mongodb to elasticsearch using logstas ...

  8. Leetcode 102 二叉树的层次遍历 Python

    二叉树的层次遍历 给定一个二叉树,返回其按层次遍历的节点值. (即逐层地,从左到右访问所有节点). 例如: 给定二叉树: [3,9,20,null,null,15,7],   3   / \ 9 20 ...

  9. canvas+js+面向对象的圆形封装

    效果: Circle.js /* 1. 封装属性: x, y r, fillStyle strokeStyle opacity 2.render */ function Circle(option) ...

  10. docker 磁盘清理 相关

    用户在使用 Docker 部署业务一段时间后,可能会发现宿主节点的磁盘容量持续增长,甚至将磁盘空间耗尽进而引发宿主机异常,进而对业务造成影响. 本文先对 Docker 的空间分析与清理进行说明,然后对 ...