锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲av无码片区一区二区三区,亚洲成人黄色网址,亚洲国产天堂久久综合网站 http://www.tkk7.com/alex/category/14971.html涓嶆眰澶氬緱,鍙眰涓寰? about java,hibernate,spring,design,database,linux,etc. <br/><br/> 鏈榪戝叧蹇冪殑鍐呭鍏抽敭瀛?web蹇熷紑鍙戞柟妗堬紝寤烘ā,workshop studio,Ajax zh-cnTue, 27 Feb 2007 14:41:28 GMTTue, 27 Feb 2007 14:41:28 GMT60[zt]Java鍔犲瘑鍜屾暟瀛楃鍚?/title><link>http://www.tkk7.com/alex/archive/2006/09/07/68398.html</link><dc:creator>Alex</dc:creator><author>Alex</author><pubDate>Thu, 07 Sep 2006 15:59:00 GMT</pubDate><guid>http://www.tkk7.com/alex/archive/2006/09/07/68398.html</guid><wfw:comment>http://www.tkk7.com/alex/comments/68398.html</wfw:comment><comments>http://www.tkk7.com/alex/archive/2006/09/07/68398.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.tkk7.com/alex/comments/commentRss/68398.html</wfw:commentRss><trackback:ping>http://www.tkk7.com/alex/services/trackbacks/68398.html</trackback:ping><description><![CDATA[ <span id="arcgsqh" class="f14">鏈枃涓昏璋堜竴涓嬪瘑鐮佸涓殑鍔犲瘑鍜屾暟瀛楃鍚嶏紝浠ュ強鍏跺湪java涓浣曡繘琛屼嬌鐢ㄣ傚瀵嗙爜瀛︽湁鍏磋叮鐨勪紮浼達紝鎺ㄨ崘鐪? Bruce Schneier鐨勮憲浣滐細Applied Crypotography銆傚湪jdk1.5鐨勫彂琛岀増鏈腑瀹夊叏鎬ф柟闈㈡湁浜嗗緢澶х殑鏀硅繘錛屼篃鎻愪緵浜嗗RSA綆楁硶鐨勭洿鎺ユ敮鎸侊紝鐜板湪鎴戜滑浠庡疄渚嬪叆鎵嬭В鍐抽棶棰橈紙鏈枃 浠呮槸浣滀負綆鍗曚粙緇嶏級錛?<br /><br />銆銆<strong>涓銆佸瘑鐮佸涓婂父鐢ㄧ殑姒傚康</strong>銆<br /><br />銆銆1錛夋秷鎭憳瑕侊細<br /><br />銆 銆榪欐槸涓縐嶄笌娑堟伅璁よ瘉鐮佺粨鍚堜嬌鐢ㄤ互紜繚娑堟伅瀹屾暣鎬х殑鎶鏈備富瑕佷嬌鐢ㄥ崟鍚戞暎鍒楀嚱鏁扮畻娉曪紝鍙敤浜庢楠屾秷鎭殑瀹屾暣鎬э紝鍜岄氳繃鏁e垪瀵嗙爜鐩存帴浠ユ枃鏈艦寮忎繚瀛樼瓑錛岀洰鍓? 騫挎硾浣跨敤鐨勭畻娉曟湁MD4銆丮D5銆丼HA-1錛宩dk1.5瀵逛笂闈㈤兘鎻愪緵浜嗘敮鎸侊紝鍦╦ava涓繘琛屾秷鎭憳瑕佸緢綆鍗曪紝 java.security.MessageDigest鎻愪緵浜嗕竴涓畝鏄撶殑鎿嶄綔鏂規硶錛?br /><br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br />*MessageDigestExample.java<br />*Copyright聽2005-2-16<br /></span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);">聽java.security.MessageDigest;<br /></span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br />*鍗曚竴鐨勬秷鎭憳瑕佺畻娉曪紝涓嶄嬌鐢ㄥ瘑鐮?鍙互鐢ㄦ潵瀵規槑鏂囨秷鎭紙濡傦細瀵嗙爜錛夐殣钘忎繚瀛?br /></span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">聽MessageDigestExample{<br />銆</span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);">聽main(String[]聽args)聽</span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);">聽Exception{<br />銆銆</span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(args.length</span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">){<br />銆銆銆System.err.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Usage:java聽MessageDigestExample聽text</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />銆銆銆System.exit(</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">);<br />銆銆}<br /><br />銆銆</span><span style="color: rgb(0, 0, 255);">byte</span><span style="color: rgb(0, 0, 0);">[]聽plainText</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">args[</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">].getBytes(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">UTF8</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br /><br />銆銆</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">浣跨敤getInstance("綆楁硶")鏉ヨ幏寰楁秷鎭憳瑕?榪欓噷浣跨敤SHA-1鐨?60浣嶇畻娉?/span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">銆銆MessageDigest聽messageDigest</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">MessageDigest.getInstance(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">SHA-1</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br /><br />銆銆System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">\n</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">messageDigest.getProvider().getInfo());<br />銆銆</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">寮濮嬩嬌鐢ㄧ畻娉?/span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">銆銆messageDigest.update(plainText);<br />銆銆System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">\nDigest:</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />銆銆</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">杈撳嚭綆楁硶榪愮畻緇撴灉</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">銆銆System.out.println(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);">聽String(messageDigest.digest(),</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">UTF8</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">));<br />銆}<br />}</span></div><br />銆銆榪樺彲浠ラ氳繃娑堟伅璁よ瘉鐮佹潵榪涜鍔犲瘑瀹炵幇錛宩avax.crypto.Mac鎻愪緵浜嗕竴涓В鍐蟲柟妗堬紝鏈夊叴瓚h呭彲浠ュ弬鑰冪浉鍏矨PI鏂囨。錛屾湰鏂囧彧鏄畝鍗曚粙緇嶄粈涔堟槸鎽樿綆楁硶銆?br /><br />榪欓噷琛ュ厖鍙︿竴涓繍鐢ㄦ秷鎭憳瑕佺殑鏂瑰紡鍔犲瘑鐨勪緥瀛?<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">聽TestEncrypt聽{<br /><br />聽聽聽聽</span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">聽TestEncrypt()聽{<br />聽聽聽聽}<br /><br />聽聽聽聽</span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br />聽聽聽聽聽*聽</span><span style="color: rgb(128, 128, 128);">@param</span><span style="color: rgb(0, 128, 0);">聽strSrc聽聽:strSrc聽is聽a聽string聽will聽be聽encrypted,<br />聽聽聽聽聽*聽</span><span style="color: rgb(128, 128, 128);">@param</span><span style="color: rgb(0, 128, 0);">聽encName聽:聽encName聽is聽the聽algorithm聽name聽will聽be聽used.<br />聽聽聽聽聽*聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽encName聽dafault聽to聽"MD5"<br />聽聽聽聽聽*聽</span><span style="color: rgb(128, 128, 128);">@return</span><span style="color: rgb(0, 128, 0);">聽String<br />聽聽聽聽聽</span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br />聽聽聽聽</span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">聽String聽Encrypt(String聽strSrc,聽String聽encName)聽{<br /><br />聽聽聽聽聽聽聽聽MessageDigest聽md聽</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">;<br />聽聽聽聽聽聽聽聽String聽strDes聽</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">;<br /><br />聽聽聽聽聽聽聽聽</span><span style="color: rgb(0, 0, 255);">byte</span><span style="color: rgb(0, 0, 0);">[]聽bt聽</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">聽strSrc.getBytes();<br />聽聽聽聽聽聽聽聽</span><span style="color: rgb(0, 0, 255);">try</span><span style="color: rgb(0, 0, 0);">聽{<br />聽聽聽聽聽聽聽聽聽聽聽聽</span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">聽(encName聽</span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 0);">||</span><span style="color: rgb(0, 0, 0);">聽encName.equals(</span><span style="color: rgb(0, 0, 0);">""</span><span style="color: rgb(0, 0, 0);">))聽{<br />聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽encName聽</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">MD5</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">;<br />聽聽聽聽聽聽聽聽聽聽聽聽}<br />聽聽聽聽聽聽聽聽聽聽聽聽md聽</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">聽MessageDigest.getInstance(encName);<br />聽聽聽聽聽聽聽聽聽聽聽聽md.update(bt);<br />聽聽聽聽聽聽聽聽聽聽聽聽strDes聽</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">聽bytes2Hex(md.digest());聽</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">to聽HexString</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">聽聽聽聽聽聽聽聽}<br />聽聽聽聽聽聽聽聽</span><span style="color: rgb(0, 0, 255);">catch</span><span style="color: rgb(0, 0, 0);">聽(NoSuchAlgorithmException聽e)聽{<br />聽聽聽聽聽聽聽聽聽聽聽聽System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Invalid聽algorithm.</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />聽聽聽聽聽聽聽聽聽聽聽聽</span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">;<br />聽聽聽聽聽聽聽聽}<br />聽聽聽聽聽聽聽聽</span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);">聽strDes;<br />聽聽聽聽}<br /><br />聽聽聽聽</span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">聽String聽bytes2Hex(</span><span style="color: rgb(0, 0, 255);">byte</span><span style="color: rgb(0, 0, 0);">[]聽bts)聽{<br />聽聽聽聽聽聽聽聽String聽des聽</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 0);">""</span><span style="color: rgb(0, 0, 0);">;<br />聽聽聽聽聽聽聽聽String聽tmp聽</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">;<br />聽聽聽聽聽聽聽聽</span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);">聽(</span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);">聽i聽</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">;聽i聽</span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">聽bts.length;聽i</span><span style="color: rgb(0, 0, 0);">++</span><span style="color: rgb(0, 0, 0);">)聽{<br />聽聽聽聽聽聽聽聽聽聽聽聽tmp聽</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">聽(Integer.toHexString(bts[i]聽</span><span style="color: rgb(0, 0, 0);">&</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 0);">0xFF</span><span style="color: rgb(0, 0, 0);">));<br />聽聽聽聽聽聽聽聽聽聽聽聽</span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">聽(tmp.length()聽</span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">)聽{<br />聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽des聽</span><span style="color: rgb(0, 0, 0);">+=</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">;<br />聽聽聽聽聽聽聽聽聽聽聽聽}<br />聽聽聽聽聽聽聽聽聽聽聽聽des聽</span><span style="color: rgb(0, 0, 0);">+=</span><span style="color: rgb(0, 0, 0);">聽tmp;<br />聽聽聽聽聽聽聽聽}<br />聽聽聽聽聽聽聽聽</span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);">聽des;<br />聽聽聽聽}<br /><br />聽聽聽聽</span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);">聽main(String[]args)聽{<br />聽聽聽聽聽聽聽聽TestEncrypt聽te聽</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);">聽TestEncrypt();<br />聽聽聽聽聽聽聽聽String聽strSrc聽</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">鍙互鍔犲瘑姹夊瓧.Oh,and聽english</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">;<br />聽聽聽聽聽聽聽聽System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Source聽String:</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">聽strSrc);<br />聽聽聽聽聽聽聽聽System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Encrypted聽String:</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />聽聽聽聽聽聽聽聽System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Use聽Def:</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">聽te.Encrypt(strSrc,聽</span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">));<br />聽聽聽聽聽聽聽聽System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Use聽MD5:</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">聽te.Encrypt(strSrc,聽</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">MD5</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">));<br />聽聽聽聽聽聽聽聽System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Use聽SHA:</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">聽te.Encrypt(strSrc,聽</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">SHA-1</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">));<br />聽聽聽聽聽聽聽聽System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Use聽SHA-256:</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">聽te.Encrypt(strSrc,聽</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">SHA-256</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">));<br />聽聽聽聽}<br />}</span></div><br />鍙﹀錛屽湪javawebparts涓殑 RequestHelpers閲岀殑generateGUID鏂規硶涔熸秹鍙婂埌浜哅D5鐨勬柟娉曪紝浠g爜濡備笅:<br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(0, 0, 0);">聽String聽generateGUID(HttpServletRequest聽request)聽{<br /><br />聽聽聽聽String聽out聽</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 0);">""</span><span style="color: rgb(0, 0, 0);">;<br />聽聽聽聽</span><span style="color: rgb(0, 0, 255);">try</span><span style="color: rgb(0, 0, 0);">聽{<br />聽聽聽聽聽聽</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">聽Construct聽a聽string聽that聽is聽comprised聽of:<br />聽聽聽聽聽聽</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">聽Remote聽IP聽Address聽+聽Host聽IP聽Address聽+聽Date聽(yyyyMMdd)聽+<br />聽聽聽聽聽聽</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">聽Time聽(hhmmssSSa)聽+聽Requested聽Path聽+聽Session聽ID聽+<br />聽聽聽聽聽聽</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">聽HashCode聽Of聽ParameterMap</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">聽聽聽聽聽聽StringBuffer聽sb聽</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);">聽StringBuffer(</span><span style="color: rgb(0, 0, 0);">1024</span><span style="color: rgb(0, 0, 0);">);<br />聽聽聽聽聽聽sb.append(request.getRemoteAddr());<br />聽聽聽聽聽聽InetAddress聽ia聽</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">聽InetAddress.getLocalHost();<br />聽聽聽聽聽聽sb.append(ia.getHostAddress());<br />聽聽聽聽聽聽sb.append(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);">聽SimpleDateFormat(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">yyyyMMddhhmmssSSa</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">).format(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);">聽Date()));<br />聽聽聽聽聽聽String聽path聽</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">聽request.getServletPath();<br />聽聽聽聽聽聽String聽pathInfo聽</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">聽request.getPathInfo();<br />聽聽聽聽聽聽</span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">聽(pathInfo聽</span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">)聽{<br />聽聽聽聽聽聽聽聽path聽</span><span style="color: rgb(0, 0, 0);">+=</span><span style="color: rgb(0, 0, 0);">聽pathInfo;<br />聽聽聽聽聽聽}<br />聽聽聽聽聽聽sb.append(path);<br />聽聽聽聽聽聽sb.append(request.getSession(</span><span style="color: rgb(0, 0, 255);">false</span><span style="color: rgb(0, 0, 0);">));<br />聽聽聽聽聽聽sb.append(request.getParameterMap().hashCode());<br />聽聽聽聽聽聽String聽str聽</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">聽sb.toString();<br />聽聽聽聽聽聽</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">聽Now聽encode聽the聽string聽using聽an聽MD5聽encryption聽algorithm.</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">聽聽聽聽聽聽MessageDigest聽md聽</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">聽MessageDigest.getInstance(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">md5</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />聽聽聽聽聽聽md.update(str.getBytes());<br />聽聽聽聽聽聽</span><span style="color: rgb(0, 0, 255);">byte</span><span style="color: rgb(0, 0, 0);">[]聽digest聽</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">聽md.digest();<br />聽聽聽聽聽聽StringBuffer聽hexStr聽</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);">聽StringBuffer(</span><span style="color: rgb(0, 0, 0);">1024</span><span style="color: rgb(0, 0, 0);">);<br />聽聽聽聽聽聽</span><span style="color: rgb(0, 0, 255);">for</span><span style="color: rgb(0, 0, 0);">聽(</span><span style="color: rgb(0, 0, 255);">int</span><span style="color: rgb(0, 0, 0);">聽i聽</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">;聽i聽</span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">聽digest.length;聽i</span><span style="color: rgb(0, 0, 0);">++</span><span style="color: rgb(0, 0, 0);">)聽{<br />聽聽聽聽聽聽聽聽str聽</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">聽Integer.toHexString(</span><span style="color: rgb(0, 0, 0);">0xFF</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 0);">&</span><span style="color: rgb(0, 0, 0);">聽digest[i]);<br />聽聽聽聽聽聽聽聽</span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">聽(str.length()聽</span><span style="color: rgb(0, 0, 0);"><</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 0);">2</span><span style="color: rgb(0, 0, 0);">)聽{<br />聽聽聽聽聽聽聽聽聽聽str聽</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">聽str;<br />聽聽聽聽聽聽聽聽}<br />聽聽聽聽聽聽聽聽hexStr.append(str);<br />聽聽聽聽聽聽}<br />聽聽聽聽聽聽out聽</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">聽hexStr.toString();<br />聽聽聽聽}聽</span><span style="color: rgb(0, 0, 255);">catch</span><span style="color: rgb(0, 0, 0);">聽(NoSuchAlgorithmException聽nsae)聽{<br />聽聽聽聽聽聽log.error(nsae);<br />聽聽聽聽}聽</span><span style="color: rgb(0, 0, 255);">catch</span><span style="color: rgb(0, 0, 0);">聽(UnknownHostException聽uhe)聽{<br />聽聽聽聽聽聽log.error(uhe);<br />聽聽聽聽}<br />聽聽聽聽</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">聽Return聽the聽encrypted聽string.聽聽It聽should聽be聽unique聽based聽on聽the<br />聽聽聽聽</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">聽components聽that聽comprise聽the聽plain聽text聽string,聽and聽should聽always聽be<br />聽聽聽聽</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">聽32聽characters聽thanks聽to聽the聽MD5聽algorithm.</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">聽聽聽聽</span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);">聽out;<br /><br />聽聽}聽</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">聽End聽generateGUID().</span></div><br /><br />銆銆2錛夌閽ュ姞瀵嗭細<br /><br />銆銆娑堟伅鎽樿鍙兘媯鏌ユ秷鎭殑瀹屾暣鎬э紝浣嗘槸鍗曞悜鐨勶紝瀵規槑鏂囨秷鎭茍涓嶈兘鍔犲瘑錛岃鍔犲瘑鏄庢枃鐨勬秷鎭殑璇濓紝灝辮浣跨敤鍏朵粬鐨勭畻娉曪紝瑕佺‘淇濇満瀵嗘э紝鎴戜滑闇瑕佷嬌鐢ㄧ閽ュ瘑鐮佹湳鏉ヤ氦鎹㈢鏈夋秷鎭?br /><br />銆銆榪欑鏈濂界悊瑙o紝浣跨敤瀵圭О綆楁硶銆傛瘮濡傦細A鐢ㄤ竴涓瘑閽ュ涓涓枃浠跺姞瀵嗭紝鑰孊璇誨彇榪欎釜鏂囦歡鐨勮瘽錛屽垯闇瑕佸拰A涓鏍風殑瀵嗛挜錛屽弻鏂瑰叡浜竴涓閽ワ紙鑰屽湪web鐜涓嬶紝縐侀挜鍦ㄤ紶閫掓椂瀹規槗琚睛鍚級錛?br /><br />銆 銆浣跨敤縐侀挜鍔犲瘑鐨勮瘽錛岄鍏堥渶瑕佷竴涓瘑閽ワ紝鍙敤javax.crypto.KeyGenerator浜х敓涓涓瘑閽?java.security.Key), 鐒跺悗浼犻掔粰涓涓姞瀵嗗伐鍏?javax.crypto.Cipher),璇ュ伐鍏峰啀浣跨敤鐩稿簲鐨勭畻娉曟潵榪涜鍔犲瘑錛屼富瑕佸縐扮畻娉曟湁錛欴ES錛堝疄闄呭瘑閽ュ彧鐢ㄥ埌56 浣嶏級錛孉ES錛堟敮鎸佷笁縐嶅瘑閽ラ暱搴︼細128銆?92銆?56浣嶏級錛岄氬父棣栧厛128浣嶏紝鍏朵粬鐨勮繕鏈塂ESede絳夛紝jdk1.5縐嶄篃鎻愪緵浜嗗瀵圭О綆楁硶鐨勬敮鎸侊紝 浠ヤ笅渚嬪瓙浣跨敤AES綆楁硶鏉ュ姞瀵嗭細<br /><br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br />*PrivateExmaple.java<br />*Copyright聽2005-2-16<br /></span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);">聽javax.crypto.Cipher;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);">聽javax.crypto.KeyGenerator;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);">聽java.security.Key;<br /><br /></span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br />*縐侀垍鍔犲瘑錛屼繚璇佹秷鎭満瀵嗘?br /></span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">聽PrivateExample{<br />銆</span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);">聽main(String[]聽args)聽</span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);">聽Exception{<br />銆銆</span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(args.length</span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">){<br />銆銆銆System.err.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Usage:java聽PrivateExample聽<text></span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />銆銆銆System.exit(</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">);<br />銆銆}<br />銆銆</span><span style="color: rgb(0, 0, 255);">byte</span><span style="color: rgb(0, 0, 0);">[]聽plainText</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">args[</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">].getBytes(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">UTF8</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br /><br />銆銆</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">閫氳繃KeyGenerator褰㈡垚涓涓猭ey</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">銆銆System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">\nStart聽generate聽AES聽key</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />銆銆KeyGenerator聽keyGen</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">KeyGenerator.getInstance(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">AES</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />銆銆keyGen.init(</span><span style="color: rgb(0, 0, 0);">128</span><span style="color: rgb(0, 0, 0);">);<br />銆銆Key聽key</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">keyGen.generateKey();<br />銆銆System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Finish聽generating聽DES聽key</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br /><br />銆銆</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">鑾峰緱涓涓閳呭姞瀵嗙被Cipher錛孍CB鏄姞瀵嗘柟寮忥紝PKCS5Padding鏄~鍏呮柟娉?/span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">銆銆Cipher聽cipher</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">Cipher.getInstance(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">AES/ECB/PKCS5Padding</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />銆銆System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">\n</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">cipher.getProvider().getInfo());<br /><br />銆銆</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">浣跨敤縐侀垍鍔犲瘑</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">銆銆System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">\nStart聽encryption:</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />銆銆cipher.init(Cipher.ENCRYPT_MODE,key);<br />銆銆</span><span style="color: rgb(0, 0, 255);">byte</span><span style="color: rgb(0, 0, 0);">[]聽cipherText</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">cipher.doFinal(plainText);<br />銆銆System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Finish聽encryption:</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />銆銆System.out.println(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);">聽String(cipherText,</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">UTF8</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">));<br /><br />銆銆System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">\nStart聽decryption:</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />銆銆cipher.init(Cipher.DECRYPT_MODE,key);<br />銆銆</span><span style="color: rgb(0, 0, 255);">byte</span><span style="color: rgb(0, 0, 0);">[]聽newPlainText</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">cipher.doFinal(cipherText);<br />銆銆System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Finish聽decryption:</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br /><br />銆銆System.out.println(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);">聽String(newPlainText,</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">UTF8</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">));<br /><br />銆}<br />}</span></div><br />銆銆3錛夊叕閽ュ姞瀵嗭細<br /><br />銆 銆涓婇潰鎻愬埌錛岀閽ュ姞瀵嗛渶瑕佷竴涓叡浜殑瀵嗛挜錛岄偅涔堝浣曚紶閫掑瘑閽ュ憿錛焪eb鐜涓嬶紝鐩存帴浼犻掔殑璇濆緢瀹規槗琚睛鍚埌錛屽垢濂芥湁浜嗗叕閽ュ姞瀵嗙殑鍑虹幇銆傚叕閽ュ姞瀵嗕篃鍙笉瀵圭О 鍔犲瘑錛屼笉瀵圭О綆楁硶浣跨敤涓瀵瑰瘑閽ュ錛屼竴涓叕閽ワ紝涓涓閽ワ紝浣跨敤鍏挜鍔犲瘑鐨勬暟鎹紝鍙湁縐侀挜鑳借В寮錛堝彲鐢ㄤ簬鍔犲瘑錛夛紱鍚屾椂錛屼嬌鐢ㄧ閽ュ姞瀵嗙殑鏁版嵁錛屽彧鏈夊叕閽ヨ兘瑙e紑 錛堢鍚嶏級銆備絾鏄熷害寰堟參錛堟瘮縐侀挜鍔犲瘑鎱?00鍒?000鍊嶏級錛屽叕閽ョ殑涓昏綆楁硶鏈塕SA錛岃繕鍖呮嫭Blowfish,Diffie-Helman絳夛紝 jdk1.5縐嶆彁渚涗簡瀵筊SA鐨勬敮鎸侊紝鏄竴涓敼榪涚殑鍦版柟錛?<br /><br /><div style="border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; background-color: rgb(238, 238, 238); font-size: 13px; width: 98%;"><!--<br><br>Code highlighting produced by Actipro CodeHighlighter (freeware)<br>http://www.CodeHighlighter.com/<br><br>--><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br />*PublicExample.java<br />*Copyright聽2005-2-16<br /></span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);">聽java.security.Key;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);">聽javax.crypto.Cipher;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);">聽java.security.KeyPairGenerator;<br /></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);">聽java.security.KeyPair;<br /></span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br />*涓涓畝鍗曠殑鍏垍鍔犲瘑渚嬪瓙,Cipher綾諱嬌鐢↘eyPairGenerator鐢熸垚鐨勫叕閳呭拰縐侀垍<br /></span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">聽PublicExample{<br />銆</span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 255);">static</span><span style="color: rgb(0, 0, 0);">聽</span><span style="color: rgb(0, 0, 255);">void</span><span style="color: rgb(0, 0, 0);">聽main(String[]聽args)聽</span><span style="color: rgb(0, 0, 255);">throws</span><span style="color: rgb(0, 0, 0);">聽Exception{<br />銆銆</span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">(args.length</span><span style="color: rgb(0, 0, 0);">!=</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">){<br />銆銆銆System.err.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Usage:java聽PublicExample聽<text></span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />銆銆銆System.exit(</span><span style="color: rgb(0, 0, 0);">1</span><span style="color: rgb(0, 0, 0);">);<br />銆銆}<br /><br />銆銆</span><span style="color: rgb(0, 0, 255);">byte</span><span style="color: rgb(0, 0, 0);">[]聽plainText</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">args[</span><span style="color: rgb(0, 0, 0);">0</span><span style="color: rgb(0, 0, 0);">].getBytes(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">UTF8</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />銆銆</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">鏋勬垚涓涓猂SA瀵嗛挜</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">銆銆System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">\nStart聽generating聽RSA聽key</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />銆銆KeyPairGenerator聽keyGen</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">KeyPairGenerator.getInstance(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">RSA</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />銆銆keyGen.initialize(</span><span style="color: rgb(0, 0, 0);">1024</span><span style="color: rgb(0, 0, 0);">);<br />銆銆KeyPair聽key</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">keyGen.generateKeyPair();<br />銆銆System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Finish聽generating聽RSA聽key</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br /><br />銆銆</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">鑾峰緱涓涓猂SA鐨凜ipher綾伙紝浣跨敤鍏垍鍔犲瘑</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">銆銆Cipher聽cipher</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">Cipher.getInstance(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">RSA/ECB/PKCS1Padding</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />銆銆System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">\n</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);">cipher.getProvider().getInfo());<br /><br />銆銆System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">\nStart聽encryption</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />銆銆cipher.init(Cipher.ENCRYPT_MODE,key.getPublic());<br />銆銆</span><span style="color: rgb(0, 0, 255);">byte</span><span style="color: rgb(0, 0, 0);">[]聽cipherText</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">cipher.doFinal(plainText);<br />銆銆System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Finish聽encryption:</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />銆銆System.out.println(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);">聽String(cipherText,</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">UTF8</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">));<br /><br />銆銆</span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);">浣跨敤縐侀垍瑙e瘑</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 0, 0);">銆銆System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">\nStart聽decryption</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />銆銆cipher.init(Cipher.DECRYPT_MODE,key.getPrivate());<br />銆銆</span><span style="color: rgb(0, 0, 255);">byte</span><span style="color: rgb(0, 0, 0);">[]聽newPlainText</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">cipher.doFinal(cipherText);<br />銆銆System.out.println(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">Finish聽decryption:</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br />銆銆System.out.println(</span><span style="color: rgb(0, 0, 255);">new</span><span style="color: rgb(0, 0, 0);">聽String(newPlainText,</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">UTF8</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">));<br />銆}<br />}</span></div><br /></span> <img src ="http://www.tkk7.com/alex/aggbug/68398.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.tkk7.com/alex/" target="_blank">Alex</a> 2006-09-07 23:59 <a href="http://www.tkk7.com/alex/archive/2006/09/07/68398.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item></channel></rss> <footer> <div class="friendship-link"> <p>感谢您访问我们的网站,您可能还对以下资源感兴趣:</p> <a href="http://www.tkk7.com/" title="亚洲av成人片在线观看">亚洲av成人片在线观看</a> <div class="friend-links"> </div> </div> </footer> 主站蜘蛛池模板: <a href="http://szjmlr.com" target="_blank">免费中文字幕在线观看</a>| <a href="http://html5text.com" target="_blank">91精品免费不卡在线观看</a>| <a href="http://adcadm.com" target="_blank">男女超爽视频免费播放</a>| <a href="http://selangcun.com" target="_blank">亚洲aⅴ无码专区在线观看春色 </a>| <a href="http://222941.com" target="_blank">在线天堂免费观看.WWW</a>| <a href="http://hs969.com" target="_blank">青草草色A免费观看在线</a>| <a href="http://dasheng178.com" target="_blank">亚洲黄色免费网址</a>| <a href="http://2023852.com" target="_blank">中文字幕av无码无卡免费</a>| <a href="http://gwcyy.com" target="_blank">成年男女男精品免费视频网站</a>| <a href="http://lidajc.com" target="_blank">大学生美女毛片免费视频</a>| <a href="http://hwjyrck.com" target="_blank">成在线人永久免费视频播放</a>| <a href="http://91haikala.com" target="_blank">大地资源免费更新在线播放 </a>| <a href="http://zaidongmaixi.com" target="_blank">亚洲一区二区三区高清视频</a>| <a href="http://juguanghr.com" target="_blank">亚洲精品中文字幕乱码</a>| <a href="http://52xdc.com" target="_blank">亚洲精品国产啊女成拍色拍</a>| <a href="http://lhtjdj.com" target="_blank">亚洲AV无码一区二区三区人</a>| <a href="http://senimei9.com" target="_blank">国产亚洲福利在线视频</a>| <a href="http://www045888.com" target="_blank">久久亚洲精品无码gv</a>| <a href="http://otkaxap.com" target="_blank">免费又黄又爽又猛大片午夜 </a>| <a href="http://4438xx21.com" target="_blank">国产精品亚洲五月天高清</a>| <a href="http://gstywy.com" target="_blank">黄色a三级免费看</a>| <a href="http://zhhy68.com" target="_blank">久青草视频97国内免费影视</a>| <a href="http://556228.com" target="_blank">九九精品成人免费国产片</a>| <a href="http://shbailongma.com" target="_blank">91精品免费观看</a>| <a href="http://zhaoxinwo.com" target="_blank">久久精品a一国产成人免费网站</a>| <a href="http://sh-lkby.com" target="_blank">妞干网手机免费视频</a>| <a href="http://qq367.com" target="_blank">亚洲第一区精品观看</a>| <a href="http://aa7852.com" target="_blank">日韩亚洲欧洲在线com91tv</a>| <a href="http://yuase.com" target="_blank">亚洲成人黄色在线观看</a>| <a href="http://jack-fx.com" target="_blank">亚洲人成色77777在线观看</a>| <a href="http://xjdz8.com" target="_blank">四虎精品成人免费视频</a>| <a href="http://kph37.com" target="_blank">九九精品成人免费国产片</a>| <a href="http://btztjxc.com" target="_blank">国产又黄又爽又猛免费app</a>| <a href="http://cnpc1002.com" target="_blank">日韩精品视频免费网址</a>| <a href="http://53ggk.com" target="_blank">国产精品V亚洲精品V日韩精品</a>| <a href="http://339258.com" target="_blank">亚洲av日韩av无码</a>| <a href="http://fangdazd.com" target="_blank">亚洲最大中文字幕无码网站</a>| <a href="http://ytsp88.com" target="_blank">一级成人生活片免费看</a>| <a href="http://baizhengsh.com" target="_blank">免费一级做a爰片久久毛片潮</a>| <a href="http://dcqzr.com" target="_blank">五月天婷亚洲天综合网精品偷</a>| <a href="http://qulu999.com" target="_blank">亚洲人成影院在线观看</a>| <script> (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> </body>