锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲av无码片区一区二区三区,亚洲成人黄色网址,亚洲国产天堂久久综合网站 http://m.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://m.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://m.tkk7.com/alex/archive/2006/09/07/68398.html</guid><wfw:comment>http://m.tkk7.com/alex/comments/68398.html</wfw:comment><comments>http://m.tkk7.com/alex/archive/2006/09/07/68398.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://m.tkk7.com/alex/comments/commentRss/68398.html</wfw:commentRss><trackback:ping>http://m.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://m.tkk7.com/alex/aggbug/68398.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://m.tkk7.com/alex/" target="_blank">Alex</a> 2006-09-07 23:59 <a href="http://m.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://m.tkk7.com/" title="亚洲av成人片在线观看">亚洲av成人片在线观看</a> <div class="friend-links"> </div> </div> </footer> 主站蜘蛛池模板: <a href="http://www-741.com" target="_blank">亚洲一区二区三区深夜天堂</a>| <a href="http://69xjj.com" target="_blank">国产vA免费精品高清在线观看 </a>| <a href="http://qiwangxuan.com" target="_blank">久久成人a毛片免费观看网站</a>| <a href="http://baiyifuwu.com" target="_blank">中文字幕版免费电影网站</a>| <a href="http://www99383.com" target="_blank">国产亚洲精品免费视频播放</a>| <a href="http://666fzw.com" target="_blank">99精品视频在线观看免费</a>| <a href="http://pumanpig.com" target="_blank">午夜视频在线免费观看</a>| <a href="http://xxxxnii.com" target="_blank">三年片在线观看免费大全</a>| <a href="http://pjszlw.com" target="_blank">久久精品国产亚洲av麻豆色欲</a>| <a href="http://kmrghj.com" target="_blank">香蕉视频在线观看亚洲</a>| <a href="http://arkinbokis.com" target="_blank">亚洲午夜久久久久久尤物</a>| <a href="http://qdhengjun.com" target="_blank">美女被艹免费视频</a>| <a href="http://2h6m.com" target="_blank">久久免费动漫品精老司机 </a>| <a href="http://zzxngk.com" target="_blank">国产精品高清免费网站</a>| <a href="http://yutuzb.com" target="_blank">久久国产乱子伦免费精品</a>| <a href="http://szmazida.com" target="_blank">毛片免费全部免费观看</a>| <a href="http://yongfu-sh.com" target="_blank">亚洲日韩欧洲乱码AV夜夜摸</a>| <a href="http://caicpa.com" target="_blank">亚洲国产美女在线观看</a>| <a href="http://sd-ll.com" target="_blank">人体大胆做受免费视频</a>| <a href="http://tjbdyx.com" target="_blank">美女视频黄a视频全免费</a>| <a href="http://www12kvkv.com" target="_blank">亚洲A丁香五香天堂网</a>| <a href="http://bomilon.com" target="_blank">亚洲一卡2卡4卡5卡6卡残暴在线</a>| <a href="http://jinguwj.com" target="_blank">水蜜桃视频在线观看免费</a>| <a href="http://33dh2.com" target="_blank">美女扒开屁股让男人桶爽免费</a>| <a href="http://18888kj.com" target="_blank">一区二区三区四区免费视频</a>| <a href="http://cdlsy.com" target="_blank">午夜爱爱免费视频</a>| <a href="http://ssdtsz.com" target="_blank">97人伦色伦成人免费视频</a>| <a href="http://wwwbi757.com" target="_blank">在线观看无码的免费网站</a>| <a href="http://16688shop.com" target="_blank">亚洲成年轻人电影网站www</a>| <a href="http://mm9d.com" target="_blank">在线播放免费人成视频网站</a>| <a href="http://www-63228.com" target="_blank">丁香花免费完整高清观看</a>| <a href="http://xianzznn.com" target="_blank">亚洲成av人片天堂网</a>| <a href="http://023439.com" target="_blank">免费人成再在线观看网站 </a>| <a href="http://www-8812.com" target="_blank">亚洲天堂一区在线</a>| <a href="http://qzapp88.com" target="_blank">国产免费AV片在线观看</a>| <a href="http://benjiebf.com" target="_blank">gogo全球高清大胆亚洲</a>| <a href="http://wwyw99977.com" target="_blank">亚洲国产美女精品久久久</a>| <a href="http://arkinbokis.com" target="_blank">国产一卡2卡3卡4卡2021免费观看 国产一卡2卡3卡4卡无卡免费视频 </a>| <a href="http://01shanzhai.com" target="_blank">成人福利在线观看免费视频</a>| <a href="http://zengzeyu.com" target="_blank">免费a级毛片永久免费</a>| <a href="http://ju7776.com" target="_blank">亚洲老熟女五十路老熟女bbw</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>