📄 ciyawasay swanky & shumi 讓applet也可以讀寫檔案-製作signed applet.htm
字号:
您所在的城市或地區名稱為何? [Unknown]: <span class="comment">TAIPEI</span>您所在的州及省份名稱為何? [Unknown]: <span class="comment">TAIWAN</span>該單位的二字國碼為何 [Unknown]: <span class="comment">TW</span>N=Hsiao Yu Cheng, OU=CAI, O=TMTC, L=TAIPEI, ST=TAIWAN, C=TW 正確嗎? [否]: <span class="comment">y</span>輸入 <mykey> 的主密碼 (RETURN 如果和 keystore 密碼相同):<span class="comment">(按Enter)</span></pre>你也可以用 <span class="code">keytool -genkey -alias 名稱</span> 來指定key的名稱<h2>察看key</h2><pre><span class="code">keytool -list</span>輸入 keystore 密碼: <span class="comment">swanky</span>Keystore 類型: jksKeystore 提供者: SUN您的 keystore 包含 1 輸入<strong>mykey</strong>, 2004/8/24, keyEntry,認證指紋 (MD5): 17:37:2E:09:C8:C9:40:52:53:4D:F8:CA:D0:F9:EB:1C</pre>其中那個<strong>mykey</strong>就是這個key的名稱<br /><h2>匯出key</h2><pre><span class="code">keytool -export -alias mykey -file swanky.crt</span>輸入 keystore 密碼: <span class="comment">swanky</span>認證儲存在檔案 <swanky.crt></pre><h2>在jar檔簽個章</h2><pre><span class="code">jarsigner ImageViewer.jar mykey</span>Enter Passphrase for keystore: <span class="comment">swanky</span>Warning: The signer certificate will expire within six months.</pre><p>簽完章後,開啟嵌入這個Applet的HTML檔就會出現下面的畫面:<br /><img alt="result.gif" src="http://www.javaworld.com.tw/blog/archives/ciyawasay/20040824/result.gif" width="872" height="604" border="0" /><br />確認後這個Applet就可以讀取本機系統上的檔案了</p><p>執行看看:<a href="http://www.javaworld.com.tw/blog/archives/ciyawasay/20040824/applet.htm" target="_blank">Try!</a><br /><a href="http://www.javaworld.com.tw/blog/archives/ciyawasay/20040824/SignedApplet.zip">Download source file</a></p><p>另外<a href="http://ant.apache.org/" target="_blank">Ant</a>也有相關的<a href="http://ant.apache.org/manual/CoreTasks/genkey.html" target="_blank">GenKey Task</a>與<a href="http://ant.apache.org/manual/CoreTasks/signjar.html" target="_blank">SignJar</a>可以讓你迅速完成以上的動作喔~</p><p>參考文章:<ul> <ol> <li><a href="http://forum.java.sun.com/thread.jsp?forum=63&thread=132769" target="_blank">10 Steps to create a digital certificate and sign an applet</a></li> <li><a href="http://mindprod.com/jgloss/signedapplets.html" target="_blank">Java Glossary : signed Applets</a></li> </ol></ul></p>]]></dc:description><dc:creator>swanky</dc:creator><dc:date>2004-08-24T16:46:23+08:00</dc:date><license rdf:resource="http://creativecommons.org/licenses/by-nc-sa/1.0/" /></Work><License rdf:about="http://creativecommons.org/licenses/by-nc-sa/1.0/"><requires rdf:resource="http://web.resource.org/cc/Attribution" /><requires rdf:resource="http://web.resource.org/cc/Notice" /><requires rdf:resource="http://web.resource.org/cc/ShareAlike" /><permits rdf:resource="http://web.resource.org/cc/Reproduction" /><permits rdf:resource="http://web.resource.org/cc/Distribution" /><permits rdf:resource="http://web.resource.org/cc/DerivativeWorks" /><prohibits rdf:resource="http://web.resource.org/cc/CommercialUse" /></License></rdf:RDF>-->
<META content="MSHTML 6.00.3790.0" name=GENERATOR></HEAD>
<BODY>
<DIV id=banner><A accessKey=1
href="http://www.javaworld.com.tw/blog/ciyawasay/">ciyawasay : swanky &
shumi</A> <SPAN class=description>每天的幸福</SPAN> </DIV>
<DIV id=container><!--WEBBOT bot="HTMLMarkup" startspan ALT="Site Meter" -->
<SCRIPT language=JavaScript
type=text/javascript>var site="s19ciyawasay"</SCRIPT>
<SCRIPT language=JavaScript1.2
src="ciyawasay swanky & shumi 讓Applet也可以讀寫檔案-製作Signed Applet_files/counter.js"
type=text/javascript></SCRIPT>
<NOSCRIPT><A href="http://s19.sitemeter.com/stats.asp?site=s19ciyawasay"
target=_top><IMG alt="Site Meter"
src="ciyawasay swanky & shumi 讓Applet也可以讀寫檔案-製作Signed Applet_files/meter.gif"
border=0></A> </NOSCRIPT><!-- Copyright (c)2002 Site Meter --><!--WEBBOT bot="HTMLMarkup" Endspan -->
<DIV class=blog>
<DIV id=menu><A
href="http://www.javaworld.com.tw/blog/archives/ciyawasay/000303.html">«
專題現況2004/08/21</A> | <A
href="http://www.javaworld.com.tw/blog/ciyawasay/">回到主頁面</A> | <A
href="http://www.javaworld.com.tw/blog/archives/ciyawasay/000341.html">颱風與大樹
»</A> </DIV></DIV>
<DIV class=blog>
<H2 class=date>August 24, 2004</H2>
<DIV class=blogbody>
<H3 class=title>讓Applet也可以讀寫檔案-製作Signed Applet</H3>
<P>Applet由於其sand box的安全機制<BR>讓它無法自由自在地存取使用者本機系統上的檔案<BR>要讓它能夠跳脫 sand box
的束縛<BR>唯一的方式就是把它變成一個Signed
Applet<BR>這些步驟實在是很繁瑣<BR>所以我在這邊整理了一下,分享給大家<BR>如果有更方便的方法也請多指教囉~ :) </P><A
name=more></A>
<H2>首先</H2>先寫一個Applet,並把它包成JAR檔<BR>我這裡寫的是一個可以看圖片的Applet,檔名叫<SPAN
class=comment>ImageViewer.jar</SPAN><BR>並且準備一個嵌入這個Applet的HTML檔<BR>另外,要執行下述keytool與jarsigner指令,必須先確定有把JAVA_HOME/bin加入PATH中
<H2>產生key</H2><PRE><SPAN class=code>keytool -genkey</SPAN>
輸入 keystore 密碼: <SPAN class=comment>swanky</SPAN>
您的名字與姓氏為何?
[Unknown]: <SPAN class=comment>Hsiao Yu Cheng</SPAN>
您的編制單位名稱為何?
[Unknown]: <SPAN class=comment>CAI</SPAN>
您的組織名稱為何?
[Unknown]: <SPAN class=comment>TMTC</SPAN>
您所在的城市或地區名稱為何?
[Unknown]: <SPAN class=comment>TAIPEI</SPAN>
您所在的州及省份名稱為何?
[Unknown]: <SPAN class=comment>TAIWAN</SPAN>
該單位的二字國碼為何
[Unknown]: <SPAN class=comment>TW</SPAN>
N=Hsiao Yu Cheng, OU=CAI, O=TMTC, L=TAIPEI, ST=TAIWAN, C=TW 正確嗎?
[否]: <SPAN class=comment>y</SPAN>
輸入 <mykey> 的主密碼
(RETURN 如果和 keystore 密碼相同):<SPAN class=comment>(按Enter)</SPAN>
</PRE>你也可以用 <SPAN class=code>keytool -genkey -alias 名稱</SPAN> 來指定key的名稱
<H2>察看key</H2><PRE><SPAN class=code>keytool -list</SPAN>
輸入 keystore 密碼: <SPAN class=comment>swanky</SPAN>
Keystore 類型: jks
Keystore 提供者: SUN
您的 keystore 包含 1 輸入
<STRONG>mykey</STRONG>, 2004/8/24, keyEntry,
認證指紋 (MD5): 17:37:2E:09:C8:C9:40:52:53:4D:F8:CA:D0:F9:EB:1C
</PRE>其中那個<STRONG>mykey</STRONG>就是這個key的名稱<BR>
<H2>匯出key</H2><PRE><SPAN class=code>keytool -export -alias mykey -file swanky.crt</SPAN>
輸入 keystore 密碼: <SPAN class=comment>swanky</SPAN>
認證儲存在檔案 <swanky.crt>
</PRE>
<H2>在jar檔簽個章</H2><PRE><SPAN class=code>jarsigner ImageViewer.jar mykey</SPAN>
Enter Passphrase for keystore: <SPAN class=comment>swanky</SPAN>
Warning: The signer certificate will expire within six months.
</PRE>
<P>簽完章後,開啟嵌入這個Applet的HTML檔就會出現下面的畫面:<BR><IMG height=604 alt=result.gif
src="ciyawasay swanky & shumi 讓Applet也可以讀寫檔案-製作Signed Applet_files/result.gif"
width=872 border=0><BR>確認後這個Applet就可以讀取本機系統上的檔案了 </P>
<P>執行看看:<A
href="http://www.javaworld.com.tw/blog/archives/ciyawasay/20040824/applet.htm"
target=_blank>Try!</A> (p.s. 此applet是我用JDK1.5 beta2 所編譯出來的,其它版本可能會無法顯示)<BR><A
href="http://www.javaworld.com.tw/blog/archives/ciyawasay/20040824/SignedApplet.zip">Download
source file</A> </P>
<P>另外<A href="http://ant.apache.org/" target=_blank>Ant</A>也有相關的<A
href="http://ant.apache.org/manual/CoreTasks/genkey.html" target=_blank>GenKey
Task</A>與<A href="http://ant.apache.org/manual/CoreTasks/signjar.html"
target=_blank>SignJar</A>可以讓你迅速完成以上的動作喔~ </P>
<P>參考文章:
<UL>
<OL>
<LI><A
href="http://forum.java.sun.com/thread.jsp?forum=63&thread=132769"
target=_blank>10 Steps to create a digital certificate and sign an
applet</A>
<LI><A href="http://mindprod.com/jgloss/signedapplets.html"
target=_blank>Java Glossary : signed Applets</A> </LI></OL></UL>
<P></P><SPAN class=posted>由 swanky 發表於 August 24, 2004 04:46 PM | <A
onclick="OpenTrackback(this.href); return false"
href="http://www.javaworld.com.tw/blog/blog-cyokulin.cgi?__mode=view&entry_id=304">引用</A>
<BR></SPAN></DIV>
<DIV class=comments-head>反向連結</DIV>
<SCRIPT language=Javascript src="" type=text/javascript></SCRIPT>
<DIV class=comments-head><A name=comments></A>迴響</DIV>
<DIV class=comments-body>
<P>這個很cool耶</P><SPAN class=comments-post>Posted by: <A
href="http://www.javaworld.com.tw/blog/blog-comento.cgi?__mode=red&id=446">fansia</A>
發表於 2004-08-24 06:16 PM</SPAN> </DIV>
<DIV class=comments-body>
<P>好棒唷~^^*</P>
<P>--</P>
<P>風好大 雨也好大唷...</P><SPAN class=comments-post>Posted by: <A
href="mailto:shumi@fake.com">shumi</A> 發表於 2004-08-24 08:42 PM</SPAN> </DIV>
<DIV class=comments-body>
<P>請問一下<BR>包裝成Jar檔案時,是只打包就好了嗎,要建立成一個可執行的Jar檔嗎?</P><SPAN
class=comments-post>Posted by: <A href="mailto:brian_yang@yam.com">Brian</A> 發表於
2004-08-26 02:28 PM</SPAN> </DIV>
<DIV class=comments-body>
<P>只要打包就可以囉~<BR>可執行的Jar檔中<BR>要包含有main()的類別才能直接執行</P><SPAN
class=comments-post>Posted by: <A
href="http://www.javaworld.com.tw/blog/blog-comento.cgi?__mode=red&id=460">swanky</A>
發表於 2004-08-26 05:00 PM</SPAN> </DIV>
<DIV class=comments-body>
<P>請問一下jar的嵌入跟class嵌入是一樣的嗎?</P><SPAN class=comments-post>Posted by: <A
href="mailto:shihwei@mail2000.com.tw">shihwei</A> 發表於 2004-08-27 11:12 AM</SPAN>
</DIV>
<DIV class=comments-body>
<P>差不多的<BR>只是jar裡面可以包很多class</P>
<P>另外jarsigner好像沒有辦法對class做簽章的動作~</P><SPAN class=comments-post>Posted by: <A
href="http://www.javaworld.com.tw/blog/blog-comento.cgi?__mode=red&id=467">swanky</A>
發表於 2004-08-27 05:07 PM</SPAN> </DIV>
<DIV class=comments-body>
<P>請問一下<BR>run你的程式是有出現對話框<BR>但是我接受之後<BR>applet就顯示not
initiated<BR>並不能看到任何圖片<BR>請問是啥原因</P><SPAN class=comments-post>Posted by: <A
href="mailto:camel207@yahoo.com.tw">camel</A> 發表於 2005-03-10 11:18 AM</SPAN>
</DIV>
<DIV class=comments-body>
<P>可能是JDK版本不合吧<BR>我是用JDK 5.0編譯的~</P><SPAN class=comments-post>Posted by: <A
href="http://www.javaworld.com.tw/blog/blog-comento.cgi?__mode=red&id=932">swanky</A>
發表於 2005-03-10 11:34 AM</SPAN> </DIV></DIV></DIV>
<SCRIPT language=JavaScript><!--var SymRealOnLoad;var SymRealOnUnload;function SymOnUnload(){ window.open = SymWinOpen; if(SymRealOnUnload != null) SymRealOnUnload();}function SymOnLoad(){ if(SymRealOnLoad != null) SymRealOnLoad(); window.open = SymRealWinOpen; SymRealOnUnload = window.onunload; window.onunload = SymOnUnload;}SymRealOnLoad = window.onload;window.onload = SymOnLoad;//--></SCRIPT>
</BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -