下一步呢,当然就是对这个jar文件进行数字证书包装。流程如下:
<1>、生成密匙证书(key certificate),该证书将存储在你的.keystore文件中。Validity指的是密匙的有效期,默认是180,但是这里我们需要一年的时间,所以我们设置为365
keytool -genkey -alias FileFtpApplet -validity 365 -keystore FileFtpApplet.keystore
<2>、用我们的密匙来设计我们的APPLET
jarsigner -keystore FileFtpApplet.keystore FileFtpApplet.jar FileFtpApplet
<3>、导出证书
keytool -export -keystore FileFtpApplet.keystore -alias FileFtpApplet -file FileFtpApplet.cer
写一个html文件对这个applet调用:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My applet 'FileFtpApplet' starting page</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<applet codebase="."
code="yp.FileFtpApplet.class"
name="FileFtpApplet"
width="320"
height="240">
</applet>
</body>
</html>
拷贝你签名的JAR文件到放置你先前的TestApplet.html和FileFtpApplet.jar的那个目录中,然后覆盖 FileFtpApplet.jar文件。在浏览器中浏览TestApplet.html。然后你的Applet会加载,并显示一个窗口,询问你是否接受 或者拒绝这个签名的APPLET。点击“No”将以旧的未签名的版本来显示APPLET,那样它仍然位于“沙盒”中且对“外面的世界”有很多约束。点击 “Yes”将以你的APPLET获得更多的自由。这里,我们点击“Yes”,我们的APPLET被打开。