Signed jar files
2008-02-23 09:35:24来源:互联网 阅读 ()
Signed jar files
The policy file technique does not apply to Web browsers. Before you can execute FileIO
in a Web browser, you first store that Applet's classfiles in a jar file and digitally sign that jar file.
Signing a jar file requires a certificate. Although you can purchase a certificate when you want to distribute an applet commercially, I will show you how to create a free self-signed certificate (which you only use for testing). Complete the following steps to create a jar file, to create a self-signed certificate, and to sign that jar file with the certificate:
- Create the jar file: Execute
jar cvf FileIO.jar *.class
. You end up with aFileIO.jar
jar file. - Create a new key in a new keystore: Execute
keytool -genkey -keystore myKeyStore -alias me
. Alias "me" is arbitrary. It reminds you that the certificate based on the keystore is self-signed so you don't accidentally put it into production.The
keytool
prompts you for information about the new key: It asks you for a password to protect the keystore. Then it asks you for your name, department, organization, city, region, and country. This information will go into the new keystore file—myKeyStore
, in this example. - Create a self-signed test certificate based on the keystore: Execute
keytool -selfcert -alias me -keystore myKeyStore
. Enter the keystore password when prompted. - Sign the jar file with the testing certificate: Execute
jarsigner -keystore myKeyStore FileIO.jar me
. Enter the keystore password when prompted.The
jarsigner
program updates the jar file'sMETA-INF
directory to contain certificate information and digital signatures for each entry in the archive. If all goes well, you end up with a signedFileIO.jar
file.
jar
, keytool
, and jarsigner
.
Before executing the applet in a Web browser via the signed jar file, create an appropriate HTML file whose <applet>
tag includes an archive
attribute identifying the jar file. Listing 4's FileIO2.html
should do nicely.
Listing 4. FileIO2.html
<applet archive=FileIO.jar code=FileIO.class width=250 height=250>
</applet>
It's time to execute the applet. Assuming FileIO.jar
and FileIO2.html
are located in the c:\temp directory on a Windows machine, start the
Web browser and enter c:\temp\FileIO2.html into that browser's address
bar. After a few moments, a dialog box should appear. That dialog box,
as shown in Figure 2, presents a security warning and asks you to grant
permission to run the applet.
Figure 2. The Java Security Warning dialog box identifies a signed applet. Click on thumbnail to view full-sized image.
Click either the Grant This Session button or the Grant Always button to proceed. If you're curious, click the View Certificate button to view the details of the self-signed certificate that you previously created. Figure 3 shows the applet embedded in the Firefox browser.
Figure 3. The Web browser alternative to running FileIO in appletviewer
Review
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash