<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-A Cooly Weblog</title><link>http://www.blogjava.net/zpuser/</link><description /><language>zh-cn</language><lastBuildDate>Sun, 23 Nov 2008 19:03:31 GMT</lastBuildDate><pubDate>Sun, 23 Nov 2008 19:03:31 GMT</pubDate><ttl>60</ttl><item><title>Web Service理论－SOAP</title><link>http://www.blogjava.net/zpuser/archive/2008/07/04/212593.html</link><dc:creator>acooly</dc:creator><author>acooly</author><pubDate>Fri, 04 Jul 2008 09:23:00 GMT</pubDate><guid>http://www.blogjava.net/zpuser/archive/2008/07/04/212593.html</guid><wfw:comment>http://www.blogjava.net/zpuser/comments/212593.html</wfw:comment><comments>http://www.blogjava.net/zpuser/archive/2008/07/04/212593.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/zpuser/comments/commentRss/212593.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/zpuser/services/trackbacks/212593.html</trackback:ping><description><![CDATA[
		<br />
		<b>什么是WebServcie</b>
		<br />
		<br />    网上有很多解释版本。我是技术研发，所以个人理解从技术角度说：Web Service是一种轻量级别的基于XML的跨平台远程服务通讯框架技术，可以很好解决各平台和语言间的数据通讯。<br /><ul><li>语意协议：使用基于XML的SOAP协议，定义业务数据格式。</li><li>传输协议：使用HTTP,TPC/IP,FTP,SMTP和JMS等，一般采用和支持较多的是HTTP。</li><li>接口描述语言：使用基于XML的WDSL作为统一服务描述。</li></ul>简单的说，WEBSERVICE就是规定一系列的规范和框架，提供一个基于SOA（面向服务的架构）概念的使用WSDL来描述服务接口定义的方案，可以使用传统的传输协议（一般使用HTTP）传输基于XML的SOAP格式报文数据来实现跨平台间系统的通讯。下面分别介绍WEBSERVICE中必须了解的几个部分：SOAP,WSDL和传输协议<br /><b><br />SOAP</b><br /><br />简单对象访问协议（SOAP：Simple Object Access Protocol）是一种轻量的、简单的、基于 XML 的协议，它被设计成在 WEB 上交换结构化的和固化的信息。主要负责在WEBSERVICE服务中通讯报文数据格式的定义。 SOAP
可以和现存的许多因特网协议和格式结合使用，包括超文本传输协议（
HTTP），简单邮件传输协议（SMTP），多用途网际邮件扩充协议（MIME），传统SOCKET通讯(TCP/IP),JAVA消息系统(JMS)等传输协议。它还支持从消息系统到远程过程调用（RPC）等大量的应用程序。<br /><br />　SOAP 包括三个部分： 
            <ul><li>SOAP 封装：它定义了一个框架，该框架描述了消息中的内容是什么，谁应当处理它以及它是可选的还是必须的。 </li><li>SOAP 编码规则：它定义了一种序列化的机制，用于交换应用程序所定义的数据类型的实例。 </li><li>SOAP RPC 表示：它定义了用于表示远程过程调用和应答的协定。</li></ul><p>　
　SOAP 消息基本上是从发送端到接收端的单向传输，但它们常常结合起来执行类似于请求 / 应答的模式。所有的 SOAP 消息都使用 XML
编码。一条 SOAP 消息就是一个包含有一个必需的 SOAP 的封装包，一个可选的 SOAP 标头和一个必需的 SOAP 体块的 XML 文档。</p><p>　
　把 SOAP 绑定到 HTTP 提供了同时利用 SOAP 的样式和分散的灵活性的特点以及 HTTP 的丰富的特征库的优点。在 HTTP
上传送 SOAP 并不是说 SOAP 会覆盖现有的 HTTP 语义，而是 HTTP 上的 SOAP 语义会自然的映射到 HTTP 语义。在使用
HTTP 作为协议绑定的场合中， RPC 请求映射到 HTTP 请求上，而 RPC 应答映射到 HTTP 应答。<b>简单的说就是，通过HTTP POST（当然也可以GET或其它，一般是POST）方式传输一个SOAP协议定义的报文数据体，用于双向通讯。</b>然而，在 RPC 上使用
SOAP 并不仅限于 HTTP 协议绑定，也可以和其他的现行传输协议绑定。</p><p><b>语法规则</b></p><ul><li>SOAP 消息必须用 XML 来编码 
</li><li>SOAP 消息必须使用 SOAP Envelope 命名空间 
</li><li>SOAP 消息必须使用 SOAP Encoding 命名空间 
</li><li>SOAP 消息不能包含 DTD 引用 
</li><li>SOAP 消息不能包含 XML 处理指令</li></ul><p><b>SOAP报文结构</b></p><p>一条 SOAP 消息就是一个普通的 XML 文档，包含下列元素：</p><ul><li><b>必需的 Envelope标签，文档的ROOT，可把此 XML 文档标识为一条 SOAP 消息 
<br /></b>必需的 SOAP 的 Envelope 元素是 SOAP 消息的根元素。它可把 XML 文档定义为 SOAP 消息<br /></li><li>可选的 Header标签，包含头部信息<br />可选的 SOAP Header 元素可包含有关 SOAP 消息的应用程序专用信息（比如认证、支付等）。如果 Header 元素被提供，则它必须是 
Envelope 元素的第一个子元素。<br /><br /></li><li><b>必需的 Body标签，包含所有的调用和响应信息 <br /></b><p>必需的 SOAP Body 元素可包含打算传送到消息最终端点的实际 SOAP 消息。</p><p>SOAP Body 元素的直接子元素可以是合格的命名空间。SOAP 
在默认的命名空间中("http://www.w3.org/2001/12/soap-envelope")定义了 Body 元素内部的一个元素。即 SOAP 的 
Fault 元素，用于指示错误消息。</p></li><li>可选的 Fault 元素，提供有关在处理此消息所发生错误的信息<br /><p>来自 SOAP 消息的错误消息被携带于 Fault 元素内部。</p><p>如果已提供了 Fault 元素，则它必须是 Body 元素的子元素。在一条 SOAP 消息中，Fault 元素只能出现一次。</p><p>SOAP 的 Fault 元素用于下列子元素：</p><table width="434" border="1" height="112"><tbody><tr><th>子元素</th><th>描述</th></tr><tr><td>&lt;faultcode&gt;</td><td>供识别故障的代码</td></tr><tr><td>&lt;faultstring&gt;</td><td>可供人阅读的有关故障的说明</td></tr><tr><td>&lt;faultactor&gt;</td><td>有关是谁引发故障的信息</td></tr><tr><td>&lt;detail&gt;</td><td>存留涉及 Body 元素的应用程序专用错误信息</td></tr></tbody></table><br /></li></ul><b>SOAP请求报文</b><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);">&lt;!-- 信封 --&gt;<br />
&lt;</span><span style="color: rgb(128, 0, 0);">SOAP-ENV:Envelope </span><span style="color: rgb(255, 0, 0);">xmlns:SOAP-ENV</span><span style="color: rgb(0, 0, 255);">="http://schemas.xmlsoap.org/soap/envelope/"</span><span style="color: rgb(255, 0, 0);"> //SOAP报文默认命名空间<br />                   xmlns:SOAP-ENC</span><span style="color: rgb(0, 0, 255);">="http://schemas.xmlsoap.org/soap/encoding/"</span><span style="color: rgb(255, 0, 0);"> //编码数据类型命名空间<br />                   xmlns:xsi</span><span style="color: rgb(0, 0, 255);">="http://www.w3.org/2001/XMLSchema-instance"</span><span style="color: rgb(255, 0, 0);"></span><span style="color: rgb(0, 0, 0);">//文档XSD实例方案，规定格式</span><br /><span style="color: rgb(255, 0, 0);">                   xmlns:xsd</span><span style="color: rgb(0, 0, 255);">="http://www.w3.org/2001/XMLSchema"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">         //文档XSD方案，规定格式<br />    </span><span style="color: rgb(0, 0, 255);">&lt;!-- 信头 --&gt;</span><br /><span style="color: rgb(0, 0, 0);">    &lt;SOAP-ENV:HEADER&gt;&lt;/SOAP-ENV:HEADER&gt;<br /></span><span style="color: rgb(0, 0, 255);">    &lt;!-- 信体 --&gt;<br />
    &lt;</span><span style="color: rgb(128, 0, 0);">SOAP-ENV:Body</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">m:activateEpurse </span><span style="color: rgb(255, 0, 0);">xmlns:m</span><span style="color: rgb(0, 0, 255);">="http://service.payment.ipayment.justinmobile.com"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />            </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">m:appNo</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">String</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">m:appNo</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />            </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">m:mobileNo</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">String</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">m:mobileNo</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">m:activateEpurse</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">SOAP-ENV:Body</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">SOAP-ENV:Envelope</span><span style="color: rgb(0, 0, 255);">&gt;</span></div><b><br />SOAP应答报文（返回一个entry数组，也就是MAP）<br /></b><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);">&lt;</span><span style="color: rgb(128, 0, 0);">soap:Envelope </span><span style="color: rgb(255, 0, 0);">xmlns:soap</span><span style="color: rgb(0, 0, 255);">="http://schemas.xmlsoap.org/soap/envelope/"</span><span style="color: rgb(255, 0, 0);"> xmlns:xsd</span><span style="color: rgb(0, 0, 255);">="http://www.w3.org/2001/XMLSchema"</span><span style="color: rgb(255, 0, 0);"> xmlns:xsi</span><span style="color: rgb(0, 0, 255);">="http://www.w3.org/2001/XMLSchema-instance"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">soap:Body</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">ns1:activateEpurseResponse </span><span style="color: rgb(255, 0, 0);">xmlns:ns1</span><span style="color: rgb(0, 0, 255);">="http://service.payment.ipayment.justinmobile.com"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />            </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">ns1:out</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />                </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">entry </span><span style="color: rgb(255, 0, 0);">xmlns</span><span style="color: rgb(0, 0, 255);">="http://service.payment.ipayment.justinmobile.com"</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />                    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">key</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">transStatus</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">key</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />                    </span><span style="color: rgb(0, 0, 255);">&lt;</span><span style="color: rgb(128, 0, 0);">value</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);">0001</span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">value</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />                </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">entry</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />            </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">ns1:out</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />        </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">ns1:activateEpurseResponse</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br />    </span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">soap:Body</span><span style="color: rgb(0, 0, 255);">&gt;</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 0, 255);">&lt;/</span><span style="color: rgb(128, 0, 0);">soap:Envelope</span><span style="color: rgb(0, 0, 255);">&gt;</span></div><b><br /></b><p>所有以上的元素均被声明于针对 SOAP 封装的默认命名空间中：</p><p><b><a title="soap-envelope.xml" href="http://www.w3.org/2001/12/soap-envelope">http://www.w3.org/2001/12/soap-envelope</a></b></p><p>SOAP 在默认的命名空间中 ("http://www.w3.org/2001/12/soap-envelope") 
定义了三个属性。这三个属性是：actor、 mustUnderstand 以及 encodingStyle。这些被定义在 SOAP 头部的属性可定义容器如何对 
SOAP 消息进行处理。</p><h2>actor</h2><p>通过沿着消息路径经过不同的端点，SOAP 消息可从某个发送者传播到某个接收者。并非 SOAP 消息的所有部分均打算传送到 SOAP 
消息的最终端点，不过，另一个方面，也许打算传送给消息路径上的一个或多个端点。</p><p>SOAP 的 actor 属性可被用于将 Header 元素寻址到一个特定的端点。</p><p>soap:actor="URI" </p><h2>mustUnderstand</h2><p>SOAP 的 mustUnderstand 属性可用于标识标题项对于要对其进行处理的接收者来说是强制的还是可选的。</p><p>假如您向 Header 元素的某个子元素添加了 
"mustUnderstand="1"，则它可指示处理此头部的接收者必须认可此元素。假如此接收者无法认可此元素，则在处理此头部时必须失效。</p><p>soap:mustUnderstand="0|1"</p><h2>encodingStyle</h2><p>SOAP 的 encodingStyle 属性用于定义在文档中使用的数据类型。此属性可出现在任何 SOAP 
元素中，并会被应用到元素的内容及元素的所有子元素上。SOAP 消息没有默认的编码方式。</p><p>soap:encodingStyle="<a title="soap-encoding.xml" href="http://www.w3.org/2001/12/soap-encoding">http://www.w3.org/2001/12/soap-encoding</a>"</p><p><br /></p><p>以及针对 SOAP 编码和数据类型的默认命名空间：</p><p><a title="soap-encoding.xml" href="http://www.w3.org/2001/12/soap-encoding">http://www.w3.org/2001/12/soap-encoding</a></p><b><br /><br /><br /></b><b><br /><br /></b><br /><img src ="http://www.blogjava.net/zpuser/aggbug/212593.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/zpuser/" target="_blank">acooly</a> 2008-07-04 17:23 <a href="http://www.blogjava.net/zpuser/archive/2008/07/04/212593.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SVN-WINDOWS服务器架设和管理</title><link>http://www.blogjava.net/zpuser/archive/2008/06/08/206654.html</link><dc:creator>acooly</dc:creator><author>acooly</author><pubDate>Sun, 08 Jun 2008 04:40:00 GMT</pubDate><guid>http://www.blogjava.net/zpuser/archive/2008/06/08/206654.html</guid><wfw:comment>http://www.blogjava.net/zpuser/comments/206654.html</wfw:comment><comments>http://www.blogjava.net/zpuser/archive/2008/06/08/206654.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/zpuser/comments/commentRss/206654.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/zpuser/services/trackbacks/206654.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: SVN-WINDOWS														服务器架设和管理																		 																		 																										1.								   														环境和软件准备														 ...&nbsp;&nbsp;<a href='http://www.blogjava.net/zpuser/archive/2008/06/08/206654.html'>阅读全文</a><img src ="http://www.blogjava.net/zpuser/aggbug/206654.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/zpuser/" target="_blank">acooly</a> 2008-06-08 12:40 <a href="http://www.blogjava.net/zpuser/archive/2008/06/08/206654.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>RSA非对称加密JAVAAPI实现</title><link>http://www.blogjava.net/zpuser/archive/2008/05/27/203203.html</link><dc:creator>acooly</dc:creator><author>acooly</author><pubDate>Tue, 27 May 2008 05:41:00 GMT</pubDate><guid>http://www.blogjava.net/zpuser/archive/2008/05/27/203203.html</guid><wfw:comment>http://www.blogjava.net/zpuser/comments/203203.html</wfw:comment><comments>http://www.blogjava.net/zpuser/archive/2008/05/27/203203.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/zpuser/comments/commentRss/203203.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/zpuser/services/trackbacks/203203.html</trackback:ping><description><![CDATA[
		<h2> </h2>
		<p> </p>
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #0000ff">package</span>
				<span style="COLOR: #000000"> org.acooly.studio.encrypt;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">import</span>
				<span style="COLOR: #000000"> java.security.KeyPair;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">import</span>
				<span style="COLOR: #000000"> java.security.KeyPairGenerator;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">import</span>
				<span style="COLOR: #000000"> java.security.PrivateKey;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">import</span>
				<span style="COLOR: #000000"> java.security.PublicKey;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">import</span>
				<span style="COLOR: #000000"> javax.crypto.Cipher;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">import</span>
				<span style="COLOR: #000000"> org.apache.commons.logging.Log;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /></span>
				<span style="COLOR: #0000ff">import</span>
				<span style="COLOR: #000000"> org.apache.commons.logging.LogFactory;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" /><br /><img id="Codehighlighter1_286_2885_Open_Image" onclick="this.style.display='none'; Codehighlighter1_286_2885_Open_Text.style.display='none'; Codehighlighter1_286_2885_Closed_Image.style.display='inline'; Codehighlighter1_286_2885_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" /><img id="Codehighlighter1_286_2885_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_286_2885_Closed_Text.style.display='none'; Codehighlighter1_286_2885_Open_Image.style.display='inline'; Codehighlighter1_286_2885_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align="top" /></span>
				<span id="Codehighlighter1_286_2885_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/** */</span>
				<span id="Codehighlighter1_286_2885_Open_Text">
						<span style="COLOR: #008000">/**</span>
						<span style="COLOR: #008000">*****************************************************************************<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /> * 非对称加密JAVA算法演示(JAVA-SUN API实现)&lt;br&gt;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /> * &lt;b&gt;算法:RSA&lt;/b&gt;&lt;br&gt;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /> * RSA算法是第一个能同时用于加密和数字签名的算法，也易于理解和操作。<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /> * RSA是被研究得最广泛的公钥算法，从提出到现在已近二十年，经历了各种攻击的考验，逐渐为人们接受，普遍认为是目前最优秀的公钥方案之一。RSA的安全性依赖于大数的因子分解，但并没有从理论上证明破译RSA的难度与大数分解难度等价。即RSA的重大缺陷是无法从理论上把握它的保密性能如何，而且密码学界多数人士倾向于因子分解不是NPC问题。RSA的缺点主要有：A)产生密钥很麻烦，受到素数产生技术的限制，因而难以做到一次一密。B)分组长度太大，为保证安全性，n<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /> * 至少也要 600<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /> * bits以上，使运算代价很高，尤其是速度较慢，较对称密码算法慢几个数量级；且随着大数分解技术的发展，这个长度还在增加，不利于数据格式的标准化。目前，SET(Secure<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /> * Electronic Transaction)协议中要求CA采用2048比特长的密钥，其他实体使用1024比特的密钥。&lt;br&gt;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /> * 这种算法1978年就出现了，它是第一个既能用于数据加密也能用于数字签名的算法。它易于理解和操作，也很流行。算法的名字以发明者的名字命名：Ron<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /> * Rivest, AdiShamir 和Leonard Adleman。但RSA的安全性一直未能得到理论上的证明。 &lt;br&gt;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /> * RSA的安全性依赖于大数分解。公钥和私钥都是两个大素数（ 大于<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /> * 100个十进制位）的函数。据猜测，从一个密钥和密文推断出明文的难度等同于分解两个大素数的积。 &lt;br&gt;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /> * 密钥对的产生。选择两个大素数，p 和q 。计算： &lt;br&gt;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /> * n = p * q &lt;br&gt;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /> * 然后随机选择加密密钥e，要求 e 和 ( p - 1 ) * ( q - 1 ) 互质。最后，利用Euclid 算法计算解密密钥d, 满足 &lt;br&gt;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /> * e * d = 1 ( mod ( p - 1 ) * ( q - 1 ) ) &lt;br&gt;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /> * 其中n和d也要互质。数e和n是公钥，d是私钥。两个素数p和q不再需要，应该丢弃，不要让任何人知道。 &lt;br&gt;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /> * 加密信息 m（二进制表示）时，首先把m分成等长数据块 m1 ,m2,<img src="http://www.blogjava.net/images/dot.gif" />, mi ，块长s，其中 2^s &lt;= n, s 尽可能的大。对应的密文是：<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /> * &lt;br&gt;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /> * ci = mi^e ( mod n ) ( a ) &lt;br&gt;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /> * 解密时作如下计算： &lt;br&gt;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /> * mi = ci^d ( mod n ) ( b ) &lt;br&gt;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /> * RSA 可用于数字签名，方案是用 ( a ) 式签名， ( b )式验证。具体操作时考虑到安全性和 m信息量较大等因素，一般是先作 HASH 运算。<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /> * &lt;br&gt;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /> * RSA 的安全性。 &lt;br&gt;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /> * RSA的安全性依赖于大数分解，但是否等同于大数分解一直未能得到理论上的证明，因为没有证明破解RSA就一定需要作大数分解。假设存在一种无须分解大数的算法，那它肯定可以修改成为大数分解算法。目前，<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /> * RSA的一些变种算法已被证明等价于大数分解。不管怎样，分解n是最显然的攻击方法。现在，人们已能分解140多个十进制位的大素数。因此，模数n必须选大一些，因具体适用情况而定。<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /> * &lt;br&gt;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /> * RSA的速度。 &lt;br&gt;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /> * 由于进行的都是大数计算，使得RSA最快的情况也比DES慢上100倍，无论是软件还是硬件实现。速度一直是RSA的缺陷。一般来说只用于少量数据加密。 &lt;br&gt;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /> * RSA的选择密文攻击。 &lt;br&gt;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /> * RSA在选择密文攻击面前很脆弱。一般攻击者是将某一信息作一下伪装(Blind)，让拥有私钥的实体签署。然后，经过计算就可得到它所想要的信息。实际上，攻击利用的都是同一个弱点，即存在这样一个事实：乘幂保留了输入的乘法结构：<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /> * &lt;br&gt; ( XM )^d = X^d *M^d mod n &lt;br&gt;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /> * 前面已经提到，这个固有的问题来自于公钥密码系统的最有用的特征--每个人都能使用公钥。但从算法上无法解决这一问题，主要措施有两条：一条是采用好的公钥协议，保证工作过程中实体不对其他实体任意产生的信息解密，不对自己一无所知的信息签名；另一条是决不对陌生人送来的随机文档签名，签名时首先使用One-Way<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /> * Hash Function对文档作HASH处理，或同时使用不同的签名算法。在中提到了几种不同类型的攻击方法。 &lt;br&gt;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /> * RSA的公共模数攻击。 &lt;br&gt;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /> * 若系统中共有一个模数，只是不同的人拥有不同的e和d，系统将是危险的。最普遍的情况是同一信息用不同的公钥加密，这些公钥共模而且互质，那末该信息无需私钥就可得到恢复。设P为信息明文，两个加密密钥为e1和e2，公共模数是n，则：<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /> * C1 = P^e1 mod n &lt;br&gt;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /> * C2 = P^e2 mod n &lt;br&gt;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /> * 密码分析者知道n、e1、e2、C1和C2，就能得到P。 &lt;br&gt;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /> * 因为e1和e2互质，故用Euclidean算法能找到r和s，满足： &lt;br&gt;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /> * r * e1 + s * e2 = 1 &lt;br&gt;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /> * 假设r为负数，需再用Euclidean算法计算C1^(-1)，则 &lt;br&gt; ( C1^(-1) )^(-r) * C2^s = P mod n &lt;br&gt;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /> * 另外，还有其它几种利用公共模数攻击的方法。总之，如果知道给定模数的一对e和d，一是有利于攻击者分解模数，一是有利于攻击者计算出其它成对的e’和d’，而无需分解模数。解决办法只有一个，那就是不要共享模数n。&lt;br&gt;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /> * RSA的小指数攻击。<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /> * 有一种提高RSA速度的建议是使公钥e取较小的值，这样会使加密变得易于实现，速度有所提高。但这样作是不安全的，对付办法就是e和d都取较大的值。&lt;br&gt;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /> * <br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /> * </span>
						<span style="COLOR: #808080">@author</span>
						<span style="COLOR: #008000"> pu.zhang<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /> * <br /><img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" /> </span>
						<span style="COLOR: #008000">*/</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img id="Codehighlighter1_2923_5276_Open_Image" onclick="this.style.display='none'; Codehighlighter1_2923_5276_Open_Text.style.display='none'; Codehighlighter1_2923_5276_Closed_Image.style.display='inline'; Codehighlighter1_2923_5276_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockStart.gif" align="top" />
						<img id="Codehighlighter1_2923_5276_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_2923_5276_Closed_Text.style.display='none'; Codehighlighter1_2923_5276_Open_Image.style.display='inline'; Codehighlighter1_2923_5276_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedBlock.gif" align="top" />
				</span>
				<span style="COLOR: #0000ff">public</span>
				<span style="COLOR: #000000"> </span>
				<span style="COLOR: #0000ff">class</span>
				<span style="COLOR: #000000"> DisSymmetricEncryption </span>
				<span id="Codehighlighter1_2923_5276_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
						<img src="http://www.blogjava.net/images/dot.gif" />
				</span>
				<span id="Codehighlighter1_2923_5276_Open_Text">
						<span style="COLOR: #000000">{<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">private</span>
						<span style="COLOR: #000000"> Log logger </span>
						<span style="COLOR: #000000">=</span>
						<span style="COLOR: #000000"> LogFactory.getLog(DisSymmetricEncryption.</span>
						<span style="COLOR: #0000ff">class</span>
						<span style="COLOR: #000000">);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img id="Codehighlighter1_3054_3179_Open_Image" onclick="this.style.display='none'; Codehighlighter1_3054_3179_Open_Text.style.display='none'; Codehighlighter1_3054_3179_Closed_Image.style.display='inline'; Codehighlighter1_3054_3179_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_3054_3179_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_3054_3179_Closed_Text.style.display='none'; Codehighlighter1_3054_3179_Open_Image.style.display='inline'; Codehighlighter1_3054_3179_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">public</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">static</span>
						<span style="COLOR: #000000"> </span>
						<span style="COLOR: #0000ff">void</span>
						<span style="COLOR: #000000"> main(String[] args) </span>
						<span style="COLOR: #0000ff">throws</span>
						<span style="COLOR: #000000"> Exception</span>
						<span id="Codehighlighter1_3054_3179_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.blogjava.net/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_3054_3179_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />        DisSymmetricEncryption disSymmetricEncryption </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #0000ff">new</span>
								<span style="COLOR: #000000"> DisSymmetricEncryption();<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />        disSymmetricEncryption.RSAEncryption();<br /><img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />
								<br />
								<img id="Codehighlighter1_3183_3336_Open_Image" onclick="this.style.display='none'; Codehighlighter1_3183_3336_Open_Text.style.display='none'; Codehighlighter1_3183_3336_Closed_Image.style.display='inline'; Codehighlighter1_3183_3336_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
								<img id="Codehighlighter1_3183_3336_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_3183_3336_Closed_Text.style.display='none'; Codehighlighter1_3183_3336_Open_Image.style.display='inline'; Codehighlighter1_3183_3336_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_3183_3336_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/** */</span>
						<span id="Codehighlighter1_3183_3336_Open_Text">
								<span style="COLOR: #008000">/**</span>
								<span style="COLOR: #008000">
										<br />
										<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />     * &lt;b&gt;RSA加/解密JAVA-API演示&lt;/b&gt;&lt;br&gt;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />     * 加密可以用公钥，解密用私钥；或者加密用私钥，解密用公钥。 通常非对称加密是非常消耗资源的，因此可以对大数据用对称加密如：<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />     * DES或3DES，而对其对称密钥进行非对称加密，这样既保证了数据的安全，还能保证效率。<br /><img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />     </span>
								<span style="COLOR: #008000">*/</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img id="Codehighlighter1_3377_4879_Open_Image" onclick="this.style.display='none'; Codehighlighter1_3377_4879_Open_Text.style.display='none'; Codehighlighter1_3377_4879_Closed_Image.style.display='inline'; Codehighlighter1_3377_4879_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
								<img id="Codehighlighter1_3377_4879_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_3377_4879_Closed_Text.style.display='none'; Codehighlighter1_3377_4879_Open_Image.style.display='inline'; Codehighlighter1_3377_4879_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span style="COLOR: #0000ff">void</span>
						<span style="COLOR: #000000"> RSAEncryption() </span>
						<span style="COLOR: #0000ff">throws</span>
						<span style="COLOR: #000000"> Exception </span>
						<span id="Codehighlighter1_3377_4879_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.blogjava.net/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_3377_4879_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />        String algorithm </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">RSA</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />        logger.info(</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">algorithm:</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">+</span>
								<span style="COLOR: #000000">algorithm);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">明文</span>
								<span style="COLOR: #008000">
										<br />
										<img id="Codehighlighter1_3474_3505_Open_Image" onclick="this.style.display='none'; Codehighlighter1_3474_3505_Open_Text.style.display='none'; Codehighlighter1_3474_3505_Closed_Image.style.display='inline'; Codehighlighter1_3474_3505_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
										<img id="Codehighlighter1_3474_3505_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_3474_3505_Closed_Text.style.display='none'; Codehighlighter1_3474_3505_Open_Image.style.display='inline'; Codehighlighter1_3474_3505_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />
								</span>
								<span style="COLOR: #000000">        </span>
								<span style="COLOR: #0000ff">byte</span>
								<span style="COLOR: #000000">[] plainText </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> </span>
								<span id="Codehighlighter1_3474_3505_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.blogjava.net/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_3474_3505_Open_Text">
										<span style="COLOR: #000000">{ </span>
										<span style="COLOR: #000000">0</span>
										<span style="COLOR: #000000">, </span>
										<span style="COLOR: #000000">1</span>
										<span style="COLOR: #000000">, </span>
										<span style="COLOR: #000000">2</span>
										<span style="COLOR: #000000">, </span>
										<span style="COLOR: #000000">3</span>
										<span style="COLOR: #000000">, </span>
										<span style="COLOR: #000000">4</span>
										<span style="COLOR: #000000">, </span>
										<span style="COLOR: #000000">5</span>
										<span style="COLOR: #000000">, </span>
										<span style="COLOR: #000000">6</span>
										<span style="COLOR: #000000">, </span>
										<span style="COLOR: #000000">7</span>
										<span style="COLOR: #000000">, </span>
										<span style="COLOR: #000000">8</span>
										<span style="COLOR: #000000">, </span>
										<span style="COLOR: #000000">9</span>
										<span style="COLOR: #000000"> }</span>
								</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />        logger.info(</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">plainText:</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">+</span>
								<span style="COLOR: #000000">formatedHexString(plainText));<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />        <br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000"> 生成KeyPaire</span>
								<span style="COLOR: #008000">
										<br />
										<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />
								</span>
								<span style="COLOR: #000000">        KeyPairGenerator keyPairGenerator </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> KeyPairGenerator.getInstance(</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">RSA</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />        keyPairGenerator.initialize(</span>
								<span style="COLOR: #000000">1024</span>
								<span style="COLOR: #000000">);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />        KeyPair keyPair </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> keyPairGenerator.genKeyPair();<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000"> 公钥</span>
								<span style="COLOR: #008000">
										<br />
										<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />
								</span>
								<span style="COLOR: #000000">        PublicKey publickKey </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> keyPair.getPublic();<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />        logger.info(</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">PublicKey:</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">+</span>
								<span style="COLOR: #000000">formatedHexString(publickKey.getEncoded()));<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000"> 私钥</span>
								<span style="COLOR: #008000">
										<br />
										<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />
								</span>
								<span style="COLOR: #000000">        PrivateKey privateKey </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> keyPair.getPrivate();<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />        logger.info(</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">PrivateKey:</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">+</span>
								<span style="COLOR: #000000">formatedHexString(privateKey.getEncoded()));<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />        <br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />        Cipher cipher </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> Cipher.getInstance(</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">RSA</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000"> 公钥加密</span>
								<span style="COLOR: #008000">
										<br />
										<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />
								</span>
								<span style="COLOR: #000000">        cipher.init(Cipher.ENCRYPT_MODE, publickKey);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">byte</span>
								<span style="COLOR: #000000">[] publicKeyEncryptText </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> cipher.doFinal(plainText);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />        logger.info(</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">publicKeyEncryptText:</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">+</span>
								<span style="COLOR: #000000">formatedHexString(publicKeyEncryptText));<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">私钥解密</span>
								<span style="COLOR: #008000">
										<br />
										<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />
								</span>
								<span style="COLOR: #000000">        cipher.init(Cipher.DECRYPT_MODE, privateKey);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">byte</span>
								<span style="COLOR: #000000">[] privateKeyDecryptText </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> cipher.doFinal(publicKeyEncryptText);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />        logger.info(</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">privateKeyDecryptText:</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">+</span>
								<span style="COLOR: #000000">formatedHexString(privateKeyDecryptText));<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />        <br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">私钥加密</span>
								<span style="COLOR: #008000">
										<br />
										<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />
								</span>
								<span style="COLOR: #000000">        cipher.init(Cipher.ENCRYPT_MODE, privateKey);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">byte</span>
								<span style="COLOR: #000000">[] privateKeyEncryptText </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> cipher.doFinal(plainText);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />        logger.info(</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">privateKeyEncryptText:</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">+</span>
								<span style="COLOR: #000000">formatedHexString(privateKeyEncryptText));    <br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #008000">//</span>
								<span style="COLOR: #008000">公钥解密</span>
								<span style="COLOR: #008000">
										<br />
										<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />
								</span>
								<span style="COLOR: #000000">        cipher.init(Cipher.DECRYPT_MODE, publickKey);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">byte</span>
								<span style="COLOR: #000000">[] publicKeyDecryptText </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> cipher.doFinal(privateKeyEncryptText);<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />        logger.info(</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">publicKeyDecryptText:</span>
								<span style="COLOR: #000000">"</span>
								<span style="COLOR: #000000">+</span>
								<span style="COLOR: #000000">formatedHexString(publicKeyDecryptText));        <br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />        <br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />        <br /><img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />
								<br />
								<img id="Codehighlighter1_4883_4941_Open_Image" onclick="this.style.display='none'; Codehighlighter1_4883_4941_Open_Text.style.display='none'; Codehighlighter1_4883_4941_Closed_Image.style.display='inline'; Codehighlighter1_4883_4941_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
								<img id="Codehighlighter1_4883_4941_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_4883_4941_Closed_Text.style.display='none'; Codehighlighter1_4883_4941_Open_Image.style.display='inline'; Codehighlighter1_4883_4941_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    </span>
						<span id="Codehighlighter1_4883_4941_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">/** */</span>
						<span id="Codehighlighter1_4883_4941_Open_Text">
								<span style="COLOR: #008000">/**</span>
								<span style="COLOR: #008000">
										<br />
										<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />     * 转换byte数组为16进制的字符串显示方式<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />     * </span>
								<span style="COLOR: #808080">@param</span>
								<span style="COLOR: #008000"> b<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />     * </span>
								<span style="COLOR: #808080">@return</span>
								<span style="COLOR: #008000">
										<br />
										<img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />     </span>
								<span style="COLOR: #008000">*/</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img id="Codehighlighter1_4979_5272_Open_Image" onclick="this.style.display='none'; Codehighlighter1_4979_5272_Open_Text.style.display='none'; Codehighlighter1_4979_5272_Closed_Image.style.display='inline'; Codehighlighter1_4979_5272_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" />
								<img id="Codehighlighter1_4979_5272_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_4979_5272_Closed_Text.style.display='none'; Codehighlighter1_4979_5272_Open_Image.style.display='inline'; Codehighlighter1_4979_5272_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />    String formatedHexString(</span>
						<span style="COLOR: #0000ff">byte</span>
						<span style="COLOR: #000000">[] b) </span>
						<span id="Codehighlighter1_4979_5272_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
								<img src="http://www.blogjava.net/images/dot.gif" />
						</span>
						<span id="Codehighlighter1_4979_5272_Open_Text">
								<span style="COLOR: #000000">{<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />        String hs </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">""</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />        String stmp </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">""</span>
								<span style="COLOR: #000000">;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" /><br /><img id="Codehighlighter1_5057_5242_Open_Image" onclick="this.style.display='none'; Codehighlighter1_5057_5242_Open_Text.style.display='none'; Codehighlighter1_5057_5242_Closed_Image.style.display='inline'; Codehighlighter1_5057_5242_Closed_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockStart.gif" align="top" /><img id="Codehighlighter1_5057_5242_Closed_Image" style="DISPLAY: none" onclick="this.style.display='none'; Codehighlighter1_5057_5242_Closed_Text.style.display='none'; Codehighlighter1_5057_5242_Open_Image.style.display='inline'; Codehighlighter1_5057_5242_Open_Text.style.display='inline';" src="http://www.blogjava.net/images/OutliningIndicators/ContractedSubBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">for</span>
								<span style="COLOR: #000000"> (</span>
								<span style="COLOR: #0000ff">int</span>
								<span style="COLOR: #000000"> n </span>
								<span style="COLOR: #000000">=</span>
								<span style="COLOR: #000000"> </span>
								<span style="COLOR: #000000">0</span>
								<span style="COLOR: #000000">; n </span>
								<span style="COLOR: #000000">&lt;</span>
								<span style="COLOR: #000000"> b.length; n</span>
								<span style="COLOR: #000000">++</span>
								<span style="COLOR: #000000">) </span>
								<span id="Codehighlighter1_5057_5242_Closed_Text" style="BORDER-RIGHT: #808080 1px solid; BORDER-TOP: #808080 1px solid; DISPLAY: none; BORDER-LEFT: #808080 1px solid; BORDER-BOTTOM: #808080 1px solid; BACKGROUND-COLOR: #ffffff">
										<img src="http://www.blogjava.net/images/dot.gif" />
								</span>
								<span id="Codehighlighter1_5057_5242_Open_Text">
										<span style="COLOR: #000000">{<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />            stmp </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> (java.lang.Integer.toHexString(b[n] </span>
										<span style="COLOR: #000000">&amp;</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #000000">0XFF</span>
										<span style="COLOR: #000000">));<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
										<span style="COLOR: #0000ff">if</span>
										<span style="COLOR: #000000"> (stmp.length() </span>
										<span style="COLOR: #000000">==</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #000000">1</span>
										<span style="COLOR: #000000">)<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />                hs </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> hs </span>
										<span style="COLOR: #000000">+</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #000000">"</span>
										<span style="COLOR: #000000">0</span>
										<span style="COLOR: #000000">"</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #000000">+</span>
										<span style="COLOR: #000000"> stmp;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
										<span style="COLOR: #0000ff">else</span>
										<span style="COLOR: #000000">
												<br />
												<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />                hs </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> hs </span>
										<span style="COLOR: #000000">+</span>
										<span style="COLOR: #000000"> stmp;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />            </span>
										<span style="COLOR: #0000ff">if</span>
										<span style="COLOR: #000000"> (n </span>
										<span style="COLOR: #000000">&lt;</span>
										<span style="COLOR: #000000"> b.length </span>
										<span style="COLOR: #000000">-</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #000000">1</span>
										<span style="COLOR: #000000">)<br /><img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />                hs </span>
										<span style="COLOR: #000000">=</span>
										<span style="COLOR: #000000"> hs </span>
										<span style="COLOR: #000000">+</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #000000">"</span>
										<span style="COLOR: #000000"> </span>
										<span style="COLOR: #000000">"</span>
										<span style="COLOR: #000000">;<br /><img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />        }</span>
								</span>
								<span style="COLOR: #000000">
										<br />
										<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />        </span>
								<span style="COLOR: #0000ff">return</span>
								<span style="COLOR: #000000"> hs.toUpperCase();<br /><img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedSubBlockEnd.gif" align="top" />    }</span>
						</span>
						<span style="COLOR: #000000">
								<br />
								<img src="http://www.blogjava.net/images/OutliningIndicators/InBlock.gif" align="top" />    <br /><img src="http://www.blogjava.net/images/OutliningIndicators/ExpandedBlockEnd.gif" align="top" />}</span>
				</span>
				<span style="COLOR: #000000">
						<br />
						<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
				</span>
		</div>
<img src ="http://www.blogjava.net/zpuser/aggbug/203203.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/zpuser/" target="_blank">acooly</a> 2008-05-27 13:41 <a href="http://www.blogjava.net/zpuser/archive/2008/05/27/203203.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>windows下自动启动svn的svnserved脚本</title><link>http://www.blogjava.net/zpuser/archive/2008/05/25/202671.html</link><dc:creator>acooly</dc:creator><author>acooly</author><pubDate>Sat, 24 May 2008 17:34:00 GMT</pubDate><guid>http://www.blogjava.net/zpuser/archive/2008/05/25/202671.html</guid><wfw:comment>http://www.blogjava.net/zpuser/comments/202671.html</wfw:comment><comments>http://www.blogjava.net/zpuser/archive/2008/05/25/202671.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/zpuser/comments/commentRss/202671.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/zpuser/services/trackbacks/202671.html</trackback:ping><description><![CDATA[
		<div style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee">
				<img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />
				<span style="COLOR: #0000ff">set</span>
				<span style="COLOR: #000000"> WshShell </span>
				<span style="COLOR: #000000">=</span>
				<span style="COLOR: #000000"> WScript.CreateObject(</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">WScript.Shell</span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">)<br /><img src="http://www.blogjava.net/images/OutliningIndicators/None.gif" align="top" />WshShell.run </span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">svnserve -d -r <font color="#ff0066">h:/repository</font></span>
				<span style="COLOR: #000000">"</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #000000">0</span>
				<span style="COLOR: #000000">,</span>
				<span style="COLOR: #0000ff">true</span>
		</div>
		<br />把上面脚本保存为:auto_run_svnserve.vbs，然后加入到启动里面或是注册表run里面，系统启动的时候就自动启动了<span style="COLOR: #000000">svnserve服务。注意：<font color="#ff0066">红色部分为你的仓库的物理地址。</font></span><br /><img src ="http://www.blogjava.net/zpuser/aggbug/202671.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/zpuser/" target="_blank">acooly</a> 2008-05-25 01:34 <a href="http://www.blogjava.net/zpuser/archive/2008/05/25/202671.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>对成加密JAVA-API实现</title><link>http://www.blogjava.net/zpuser/archive/2008/05/23/202513.html</link><dc:creator>acooly</dc:creator><author>acooly</author><pubDate>Fri, 23 May 2008 15:21:00 GMT</pubDate><guid>http://www.blogjava.net/zpuser/archive/2008/05/23/202513.html</guid><wfw:comment>http://www.blogjava.net/zpuser/comments/202513.html</wfw:comment><comments>http://www.blogjava.net/zpuser/archive/2008/05/23/202513.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/zpuser/comments/commentRss/202513.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/zpuser/services/trackbacks/202513.html</trackback:ping><description><![CDATA[
		<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, 128);">  1</span> <span style="color: rgb(0, 0, 255);">package</span><span style="color: rgb(0, 0, 0);"> org.acooly.studio.encrypt;<br /></span><span style="color: rgb(0, 128, 128);">  2</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">  3</span> <span style="color: rgb(0, 0, 0);"></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, 128, 128);">  4</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">  5</span> <span style="color: rgb(0, 0, 0);"></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, 128, 128);">  6</span> <span style="color: rgb(0, 0, 0);"></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, 128, 128);">  7</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> javax.crypto.SecretKey;<br /></span><span style="color: rgb(0, 128, 128);">  8</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> javax.crypto.spec.IvParameterSpec;<br /></span><span style="color: rgb(0, 128, 128);">  9</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> javax.crypto.spec.SecretKeySpec;<br /></span><span style="color: rgb(0, 128, 128);"> 10</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 11</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.apache.commons.logging.Log;<br /></span><span style="color: rgb(0, 128, 128);"> 12</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 0, 255);">import</span><span style="color: rgb(0, 0, 0);"> org.apache.commons.logging.LogFactory;<br /></span><span style="color: rgb(0, 128, 128);"> 13</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 14</span> <span style="color: rgb(0, 0, 0);"></span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 15</span> <span style="color: rgb(0, 128, 0);"> * 对称加密JAVA算法演示(JAVA-SUN API实现)<br /></span><span style="color: rgb(0, 128, 128);"> 16</span> <span style="color: rgb(0, 128, 0);"> * <br /></span><span style="color: rgb(0, 128, 128);"> 17</span> <span style="color: rgb(0, 128, 0);"> * <br /></span><span style="color: rgb(0, 128, 128);"> 18</span> <span style="color: rgb(0, 128, 0);"> * </span><span style="color: rgb(128, 128, 128);">@author</span><span style="color: rgb(0, 128, 0);"> pu.zhang<br /></span><span style="color: rgb(0, 128, 128);"> 19</span> <span style="color: rgb(0, 128, 0);"> * <br /></span><span style="color: rgb(0, 128, 128);"> 20</span> <span style="color: rgb(0, 128, 0);"> </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 21</span> <span style="color: rgb(0, 0, 0);"></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);"> SymmetricEncryption {<br /></span><span style="color: rgb(0, 128, 128);"> 22</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 23</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 0);"> Log logger </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> LogFactory.getLog(SymmetricEncryption.</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">);<br /></span><span style="color: rgb(0, 128, 128);"> 24</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 25</span> <span style="color: rgb(0, 0, 0);">    </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, 128, 128);"> 26</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 27</span> <span style="color: rgb(0, 0, 0);">        SymmetricEncryption symmetricEncryption </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);"> SymmetricEncryption();<br /></span><span style="color: rgb(0, 128, 128);"> 28</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 29</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> DES</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 30</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">        symmetricEncryption.DESEncryption();<br /></span><span style="color: rgb(0, 128, 128);"> 31</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> 3DES</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 32</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">        symmetricEncryption.tripleDESEncryption();<br /></span><span style="color: rgb(0, 128, 128);"> 33</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 34</span> <span style="color: rgb(0, 0, 0);">    }<br /></span><span style="color: rgb(0, 128, 128);"> 35</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 36</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 37</span> <span style="color: rgb(0, 128, 0);">     * DES加/解密演示<br /></span><span style="color: rgb(0, 128, 128);"> 38</span> <span style="color: rgb(0, 128, 0);">     * <br /></span><span style="color: rgb(0, 128, 128);"> 39</span> <span style="color: rgb(0, 128, 0);">     * </span><span style="color: rgb(128, 128, 128);">@throws</span><span style="color: rgb(0, 128, 0);"> Exception<br /></span><span style="color: rgb(0, 128, 128);"> 40</span> <span style="color: rgb(0, 128, 0);">     </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 41</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);"> DESEncryption() </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, 128, 128);"> 42</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 43</span> <span style="color: rgb(0, 0, 0);">        </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, 128, 128);"> 44</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">        </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);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">I am plain text!</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">.getBytes();<br /></span><span style="color: rgb(0, 128, 128);"> 45</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 46</span> <span style="color: rgb(0, 0, 0);">        logger.info(</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);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> formatedHexString(plainText));<br /></span><span style="color: rgb(0, 128, 128);"> 47</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> 通过KeyGenerator形成一个key</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 48</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">        KeyGenerator keyGenerator </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);">DES</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">);<br /></span><span style="color: rgb(0, 128, 128);"> 49</span> <span style="color: rgb(0, 0, 0);">        Key key </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> keyGenerator.generateKey();<br /></span><span style="color: rgb(0, 128, 128);"> 50</span> <span style="color: rgb(0, 0, 0);">        logger.info(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">KEY:</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);"> formatedHexString(key.getEncoded()));<br /></span><span style="color: rgb(0, 128, 128);"> 51</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 52</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> 获得一个私钥加密类Cipher，CBC是加密方式，PKCS5Padding是填充方法<br /></span><span style="color: rgb(0, 128, 128);"> 53</span> <span style="color: rgb(0, 128, 0);">        </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> CBC加密方式：把明文分为左右两部分LP和RP<img src="http://www.blogjava.net/images/dot.gif" /></span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 54</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">        String transformation </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);">DES/CBC/PKCS5Padding</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">; </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> algorithm/mode/padding</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 55</span> <span style="color: rgb(0, 128, 0);"></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(transformation);<br /></span><span style="color: rgb(0, 128, 128);"> 56</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 57</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> CBC方式的初始化向量</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 58</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">byte</span><span style="color: rgb(0, 0, 0);">[] iv </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);">iamaniv.</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">.getBytes();<br /></span><span style="color: rgb(0, 128, 128);"> 59</span> <span style="color: rgb(0, 0, 0);">        IvParameterSpec ivparam </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);"> IvParameterSpec(iv);<br /></span><span style="color: rgb(0, 128, 128);"> 60</span> <span style="color: rgb(0, 0, 0);">        </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, 128, 128);"> 61</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">        cipher.init(Cipher.ENCRYPT_MODE, key, ivparam);<br /></span><span style="color: rgb(0, 128, 128);"> 62</span> <span style="color: rgb(0, 0, 0);">        </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 /></span><span style="color: rgb(0, 128, 128);"> 63</span> <span style="color: rgb(0, 0, 0);">        logger.info(</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);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> formatedHexString(cipherText));<br /></span><span style="color: rgb(0, 128, 128);"> 64</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 65</span> <span style="color: rgb(0, 0, 0);">        </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, 128, 128);"> 66</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 67</span> <span style="color: rgb(0, 0, 0);">        cipher.init(Cipher.DECRYPT_MODE, key, ivparam);<br /></span><span style="color: rgb(0, 128, 128);"> 68</span> <span style="color: rgb(0, 0, 0);">        </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 /></span><span style="color: rgb(0, 128, 128);"> 69</span> <span style="color: rgb(0, 0, 0);">        logger.info(</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);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> formatedHexString(newPlainText));<br /></span><span style="color: rgb(0, 128, 128);"> 70</span> <span style="color: rgb(0, 0, 0);">    }<br /></span><span style="color: rgb(0, 128, 128);"> 71</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 72</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 73</span> <span style="color: rgb(0, 128, 0);">     * DES加/解密演示<br /></span><span style="color: rgb(0, 128, 128);"> 74</span> <span style="color: rgb(0, 128, 0);">     * <br /></span><span style="color: rgb(0, 128, 128);"> 75</span> <span style="color: rgb(0, 128, 0);">     * </span><span style="color: rgb(128, 128, 128);">@throws</span><span style="color: rgb(0, 128, 0);"> Exception<br /></span><span style="color: rgb(0, 128, 128);"> 76</span> <span style="color: rgb(0, 128, 0);">     </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 77</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);"> tripleDESEncryption() </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, 128, 128);"> 78</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> 24字节密钥key,3倍DES密钥长度</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 79</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">byte</span><span style="color: rgb(0, 0, 0);">[] tripleKey </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);">123456789012345678901234</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">.getBytes();<br /></span><span style="color: rgb(0, 128, 128);"> 80</span> <span style="color: rgb(0, 0, 0);">        logger.info(</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">tripleKey:</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);"> formatedHexString(tripleKey));<br /></span><span style="color: rgb(0, 128, 128);"> 81</span> <span style="color: rgb(0, 0, 0);">        </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, 128, 128);"> 82</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">        </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);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">I am plain text!</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">.getBytes();<br /></span><span style="color: rgb(0, 128, 128);"> 83</span> <span style="color: rgb(0, 0, 0);">        logger.info(</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);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> formatedHexString(plainText));<br /></span><span style="color: rgb(0, 128, 128);"> 84</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 85</span> <span style="color: rgb(0, 0, 0);">        </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, 128, 128);"> 86</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">        String algorithm </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);">DESede</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">;<br /></span><span style="color: rgb(0, 128, 128);"> 87</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 88</span> <span style="color: rgb(0, 0, 0);">        </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, 128, 128);"> 89</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">        SecretKey secretKey </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);"> SecretKeySpec(tripleKey, algorithm);<br /></span><span style="color: rgb(0, 128, 128);"> 90</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 91</span> <span style="color: rgb(0, 0, 0);">        String transformation </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);">DESede/CBC/PKCS5Padding</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">;<br /></span><span style="color: rgb(0, 128, 128);"> 92</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(transformation);<br /></span><span style="color: rgb(0, 128, 128);"> 93</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 128, 0);">//</span><span style="color: rgb(0, 128, 0);"> CBC方式的初始化向量</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 94</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">byte</span><span style="color: rgb(0, 0, 0);">[] iv </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);">iamaniv.</span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">.getBytes();<br /></span><span style="color: rgb(0, 128, 128);"> 95</span> <span style="color: rgb(0, 0, 0);">        IvParameterSpec ivparam </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);"> IvParameterSpec(iv);<br /></span><span style="color: rgb(0, 128, 128);"> 96</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);"> 97</span> <span style="color: rgb(0, 0, 0);">        </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, 128, 128);"> 98</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">        cipher.init(Cipher.ENCRYPT_MODE, secretKey, ivparam);<br /></span><span style="color: rgb(0, 128, 128);"> 99</span> <span style="color: rgb(0, 0, 0);">        </span><span style="color: rgb(0, 0, 255);">byte</span><span style="color: rgb(0, 0, 0);">[] encriptText </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> cipher.doFinal(plainText);<br /></span><span style="color: rgb(0, 128, 128);">100</span> <span style="color: rgb(0, 0, 0);">        logger.info(</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);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> formatedHexString(encriptText));<br /></span><span style="color: rgb(0, 128, 128);">101</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">102</span> <span style="color: rgb(0, 0, 0);">        </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, 128, 128);">103</span> <span style="color: rgb(0, 128, 0);"></span><span style="color: rgb(0, 0, 0);">        cipher.init(Cipher.DECRYPT_MODE, secretKey, ivparam);<br /></span><span style="color: rgb(0, 128, 128);">104</span> <span style="color: rgb(0, 0, 0);">        </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(encriptText);<br /></span><span style="color: rgb(0, 128, 128);">105</span> <span style="color: rgb(0, 0, 0);">        logger.info(</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);"> </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> formatedHexString(newPlainText));<br /></span><span style="color: rgb(0, 128, 128);">106</span> <span style="color: rgb(0, 0, 0);">    }<br /></span><span style="color: rgb(0, 128, 128);">107</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">108</span> <span style="color: rgb(0, 0, 0);">    <br /></span><span style="color: rgb(0, 128, 128);">109</span> <span style="color: rgb(0, 0, 0);">    </span><span style="color: rgb(0, 128, 0);">/**</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">110</span> <span style="color: rgb(0, 128, 0);">     * 转换byte数组为16进制的字符串显示方式<br /></span><span style="color: rgb(0, 128, 128);">111</span> <span style="color: rgb(0, 128, 0);">     * </span><span style="color: rgb(128, 128, 128);">@param</span><span style="color: rgb(0, 128, 0);"> b<br /></span><span style="color: rgb(0, 128, 128);">112</span> <span style="color: rgb(0, 128, 0);">     * </span><span style="color: rgb(128, 128, 128);">@return</span><span style="color: rgb(0, 128, 0);"><br /></span><span style="color: rgb(0, 128, 128);">113</span> <span style="color: rgb(0, 128, 0);">     </span><span style="color: rgb(0, 128, 0);">*/</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">114</span> <span style="color: rgb(0, 0, 0);">    String formatedHexString(</span><span style="color: rgb(0, 0, 255);">byte</span><span style="color: rgb(0, 0, 0);">[] b) {<br /></span><span style="color: rgb(0, 128, 128);">115</span> <span style="color: rgb(0, 0, 0);">        String hs </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, 128, 128);">116</span> <span style="color: rgb(0, 0, 0);">        String stmp </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, 128, 128);">117</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">118</span> <span style="color: rgb(0, 0, 0);">        </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);"> 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);">0</span><span style="color: rgb(0, 0, 0);">; n </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);"> b.length; n</span><span style="color: rgb(0, 0, 0);">++</span><span style="color: rgb(0, 0, 0);">) {<br /></span><span style="color: rgb(0, 128, 128);">119</span> <span style="color: rgb(0, 0, 0);">            stmp </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> (java.lang.Integer.toHexString(b[n] </span><span style="color: rgb(0, 0, 0);">&amp;</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, 128, 128);">120</span> <span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (stmp.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 /></span><span style="color: rgb(0, 128, 128);">121</span> <span style="color: rgb(0, 0, 0);">                hs </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> hs </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);"> stmp;<br /></span><span style="color: rgb(0, 128, 128);">122</span> <span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 0, 255);">else</span><span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">123</span> <span style="color: rgb(0, 0, 0);">                hs </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> hs </span><span style="color: rgb(0, 0, 0);">+</span><span style="color: rgb(0, 0, 0);"> stmp;<br /></span><span style="color: rgb(0, 128, 128);">124</span> <span style="color: rgb(0, 0, 0);">            </span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);"> (n </span><span style="color: rgb(0, 0, 0);">&lt;</span><span style="color: rgb(0, 0, 0);"> b.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 /></span><span style="color: rgb(0, 128, 128);">125</span> <span style="color: rgb(0, 0, 0);">                hs </span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);"> hs </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);"> </span><span style="color: rgb(0, 0, 0);">"</span><span style="color: rgb(0, 0, 0);">;<br /></span><span style="color: rgb(0, 128, 128);">126</span> <span style="color: rgb(0, 0, 0);">        }<br /></span><span style="color: rgb(0, 128, 128);">127</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);"> hs.toUpperCase();<br /></span><span style="color: rgb(0, 128, 128);">128</span> <span style="color: rgb(0, 0, 0);">    }<br /></span><span style="color: rgb(0, 128, 128);">129</span> <span style="color: rgb(0, 0, 0);"><br /></span><span style="color: rgb(0, 128, 128);">130</span> <span style="color: rgb(0, 0, 0);">}<br /></span><span style="color: rgb(0, 128, 128);">131</span> <span style="color: rgb(0, 0, 0);"></span></div>
		<br />
<img src ="http://www.blogjava.net/zpuser/aggbug/202513.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/zpuser/" target="_blank">acooly</a> 2008-05-23 23:21 <a href="http://www.blogjava.net/zpuser/archive/2008/05/23/202513.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>对称加密和非对称加密</title><link>http://www.blogjava.net/zpuser/archive/2008/05/21/201957.html</link><dc:creator>acooly</dc:creator><author>acooly</author><pubDate>Wed, 21 May 2008 08:42:00 GMT</pubDate><guid>http://www.blogjava.net/zpuser/archive/2008/05/21/201957.html</guid><wfw:comment>http://www.blogjava.net/zpuser/comments/201957.html</wfw:comment><comments>http://www.blogjava.net/zpuser/archive/2008/05/21/201957.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/zpuser/comments/commentRss/201957.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/zpuser/services/trackbacks/201957.html</trackback:ping><description><![CDATA[
		<h2>对称加密算法</h2>
		<br />
		<a title="JAVA-API部分算法实现" href="/zpuser/archive/2008/05/23/202513.html" target="_blank">JAVA-API部分算法实现</a>
		<br />
		<br />
		<p>对称加密算法 对称加密算法是应用较早的加密算法，技术成熟。在对称加密算法中，数据发信方将明文（原始数据）和加密密钥一起经过特殊加密算法处理后，使其变成复杂的加密密文发送出去。收信方收到密文后，若想解读原文，则需要使用加密用过的密钥及相同算法的逆算法对密文进行解密，才能使其恢复成可读明文。在对称加密算法中，使用的密钥只有一个，发收信双方都使用这个密钥对数据进行加密和解密，这就要求解密方事先必须知道加密密钥。对称加密算法的特点是算法公开、计算量小、加密速度快、加密效率高。不足之处是，交易双方都使用同样钥匙，安全性得不到保证。此外，每对用户每次使用对称加密算法时，都需要使用其他人不知道的惟一钥匙，这会使得发收信双方所拥有的钥匙数量成几何级数增长，密钥管理成为用户的负担。对称加密算法在分布式网络系统上使用较为困难，主要是因为密钥管理困难，使用成本较高。在计算机专网系统中广泛使用的对称加密算法有DES和IDEA等。美国国家标准局倡导的AES即将作为新标准取代DES。</p>
		<h3>DES </h3>数据加密算法（Data Encryption Algorithm，DEA）的数据加密标准（Data Encryption Standard，DES）是规范的描述，它出自 IBM 的研究工作，并在 1997 年被美国政府正式采纳。它很可能是使用最广泛的秘钥系统，特别是在保护金融数据的安全中，最初开发的 DES 是嵌入硬件中的。通常，自动取款机（Automated Teller Machine，ATM）都使用 DES。<br />DES 使用一个 56 位的密钥以及附加的 8 位奇偶校验位，产生最大 64 位的分组大小。这是一个迭代的分组密码，使用称为 Feistel 的技术，其中将加密的文本块分成两半。使用子密钥对其中一半应用循环功能，然后将输出与另一半进行“异或”运算；接着交换这两半，这一过程会继续下去，但最后一个循环不交换。DES 使用 16 个循环。<br />攻击 DES 的主要形式被称为蛮力的或彻底密钥搜索，即重复尝试各种密钥直到有一个符合为止。如果 DES 使用 56 位的密钥，则可能的密钥数量是 2 的 56 次方个。随着计算机系统能力的不断发展，DES 的安全性比它刚出现时会弱得多，然而从非关键性质的实际出发，仍可以认为它是足够的。不过 ，DES 现在仅用于旧系统的鉴定，而更多地选择新的加密标准 — 高级加密标准（Advanced Encryption Standard，AES）。 <br />DES 的常见变体是三重 DES，使用 168 位的密钥对资料进行三次加密的一种机制；它通常（但非始终）提供极其强大的安全性。如果三个 56 位的子元素都相同，则三重 DES 向后兼容 DES。<br />IBM 曾对 DES 拥有几年的专利权，但是在 1983 年已到期，并且处于公有范围中，允许在特定条件下可以免除专利使用费而使用。<br />由于DES是加(解)密64位明(密)文，即为8个字节(8*8=64)，可以据此初步判断这是分组加密，加密的过程中会有16次循环与密钥置换过程，据此可以判断有可能是用到DES密码算法，更精确的判断还得必须懂得一点DES的加密过程。 
<h3><b>3DES</b></h3><p>3DES是DES加密算法的一种模式，它使用3条64位的密钥对数据进行三次加密。数据加密标准（DES）是美国的一种由来已久的加密标准，它使用对称密钥加密法，并于1981年被ANSI组织规范为ANSI X.3.92。DES使用56位密钥和密码块的方法，而在密码块的方法中，文本被分成64位大小的文本块然后再进行加密。比起最初的DES，3DES更为安全。<br />3DES（即Triple DES）是DES向AES过渡的加密算法（1999年，NIST将3-DES指定为过渡的加密标准），是DES的一个更安全的变形。它以DES为基本模块，通过组合分组方法设计出分组加密算法，其具体实现如下：设Ek()和Dk()代表DES算法的加密和解密过程，K代表DES算法使用的密钥，P代表明文，C代表密表，这样，<br />3DES加密过程为：C=Ek3(Dk2(Ek1(P)))<br />3DES解密过程为：P=Dk1((EK2(Dk3(C))) <br /></p><br /><h3><b>AES——对称密码新标准 </b></h3><p>对称密码体制的发展趋势将以分组密码为重点。分组密码算法通常由<a href="http://baike.baidu.com/view/934.htm" target="_blank">密钥</a>扩展算法和加密（解密）算法两部分组成。密钥扩展算法将b字节用户主密钥扩展成r个子密钥。加密算法由一个密码学上的弱函数f与r个子密钥迭代r次组成。混乱和密钥扩散是分组密码算法设计的基本原则。抵御已知明文的差分和线性攻击，可变长密钥和分组是该体制的设计要点。  <br /><br />AES是美国国家标准技术研究所NIST旨在取代<a href="http://baike.baidu.com/view/7510.htm" target="_blank">DES</a>的21世纪的加密标准。   <br /><br />AES的基本要求是，采用对称分组密码体制，密钥长度的最少支持为128、192、256，分组长度128位，算法应易于各种硬件和软件实现。1998年 NIST开始AES第一轮分析、测试和征集，共产生了15个候选算法。1999年3月完成了第二轮AES2的分析、测试。预计在2000年8月AES的最终结果将公布。    <br />   <br />在应用方面，尽管DES在安全上是脆弱的，但由于快速DES芯片的大量生产，使得DES仍能暂时继续使用，为提高安全强度，通常使用独立密钥的三级DES。但是DES迟早要被AES代替。流密码体制较之分组密码在理论上成熟且安全，但未被列入下一代加密标准。   <br /></p><p><br /></p><h2>非对称加密算法</h2><p>asymmetric encoding algorithm<br />非对称加密算法需要两个密钥：公开密钥（publickey）和私有密钥（privatekey）。公开密钥与私有密钥是一对，如果用公开密钥对数据进行加密，只有用对应的私有密钥才能解密；如果用私有密钥对数据进行加密，那么只有用对应的公开密钥才能解密。因为加密和解密使用的是两个不同的密钥，所以这种算法叫作非对称加密算法。 非对称加密算法实现机密信息交换的基本过程是：甲方生成一对密钥并将其中的一把作为公用密钥向其它方公开；得到该公用密钥的乙方使用该密钥对机密信息进行加密后再发送给甲方；甲方再用自己保存的另一把专用密钥对加密后的信息进行解密。甲方只能用其专用密钥解密由其公用密钥加密后的任何信息。 非对称加密算法的保密性比较好，它消除了最终用户交换密钥的需要。<br /><br /><a href="/zpuser/archive/2008/05/27/203203.html" target="_blank">RSA算法演示<br /></a><br /><br /></p><h2>对称和非对称加密算法案例</h2><div class="t1">基于多级密钥管理体系中的对称密钥传输保护方法</div><div class="t2">申请号/专利号： 200610147335</div><div class="con2">一种基于在多级密钥管理体系中的对称密钥传输保护方法，其步骤为：<br />１．传入方签发并通过两条途径传递两张密钥传输卡，每张卡中存有一段传入方的根公钥；<br />２．传出方从两张卡获得传入方的根公钥，并随机生成传输密钥，再用该根公钥加密后分段写入到两张卡中，其工作密钥用传输密钥传出并写入两张卡中通过两条途径递送给传入方；<br />３．传入方验证卡的合法性；从两张卡中获得传输密钥和工作密钥密文并用根私钥解密传输密钥写入加密机传输密钥区；传入方将工作密钥密文通过传输密钥写入工作密钥区，从而完成了两台密钥管理加密机之间的密钥传递过程。本发明采用证书方式，加强了对称密钥传输时的安全性，采用ＩＣ卡作为介质，保证了传输介质的安全。</div><p></p><table class="tb" cellspacing="1" cellpadding="0" width="100%" border="0"><tbody><tr><td class="td1">申请日：</td><td>2006年12月15日</td></tr><tr><td class="td1">公开日：</td><td>2007年06月06日</td></tr><tr><td class="td1">授权公告日：</td><td><br /></td></tr><tr><td class="td1">申请人/专利权人：</td><td>上海格尔软件股份有限公司</td></tr><tr><td class="td1">申请人地址：</td><td>上海市闸北区余姚路288号A座4层</td></tr><tr><td class="td1">发明设计人：</td><td>张翔;杨茂江;李澜涛</td></tr><tr><td class="td1">专利代理机构：</td><td><br /></td></tr><tr><td class="td1">代理人：</td><td>陈学雯</td></tr><tr><td class="td1">专利类型：</td><td>发明专利</td></tr><tr><td class="td1">分类号：</td><td>H04L9/32;H04L9/14;H04L9/12;H04L9/08;H04L9/30</td></tr></tbody></table><img src ="http://www.blogjava.net/zpuser/aggbug/201957.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/zpuser/" target="_blank">acooly</a> 2008-05-21 16:42 <a href="http://www.blogjava.net/zpuser/archive/2008/05/21/201957.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>开发小经验汇总</title><link>http://www.blogjava.net/zpuser/archive/2007/09/17/121209.html</link><dc:creator>acooly</dc:creator><author>acooly</author><pubDate>Mon, 17 Sep 2007 03:30:00 GMT</pubDate><guid>http://www.blogjava.net/zpuser/archive/2007/09/17/121209.html</guid><wfw:comment>http://www.blogjava.net/zpuser/comments/121209.html</wfw:comment><comments>http://www.blogjava.net/zpuser/archive/2007/09/17/121209.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/zpuser/comments/commentRss/121209.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/zpuser/services/trackbacks/121209.html</trackback:ping><description><![CDATA[1.<b>回车转换行</b>：onkeypress="if(event.keyCode == 13){//do script!}<br />2.<b>Tomcat-linux环境图形显示问题：</b>JAVA_OPTS="$JAVA_OPTS -Djava.awt.headless=true"<br /><b>3.Eclipse启动参数</b>：D:\eclipse3.2\eclipse.exe  -data D:\workspace -product com.genuitec.myeclipse.product.ide -vmargs -Duser.language=en -Xms128M -Xmx512M -XX:PermSize=256M -XX:MaxPermSize=512M<br /><b>4.eclipse生成javadoc乱码解决</b>：加入参数“-encoding UTF-8 -charset UTF-8”<br /><b>5.jsp页面禁止缓存代码</b>：<br />    response.setHeader("Pragma","No-cache"); 
<br />    response.setHeader("Cache-Control","no-cache"); 
<br />    response.setDateHeader("Expires", 0); <br /><br /><b>6.linux－mount samba</b><br />   mount -t smbfs -o codepage=cp936 远程路径 本地路径 <br /><br /><b>7.查看端口对应PID</b><br />
lsof -i tcp:PORT-NO, eg, lsof -i tcp:80<br />
lsof -i udp:PORT-NO, eg, lsof -i udp:53<br /><br /><b>8.RH5.0下smbmount的代替方法</b><br />mount -t cifs //ip/f /location/dir ...<br /><br /><img src ="http://www.blogjava.net/zpuser/aggbug/121209.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/zpuser/" target="_blank">acooly</a> 2007-09-17 11:30 <a href="http://www.blogjava.net/zpuser/archive/2007/09/17/121209.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>ORACLE 禁用/启用外键和触发器</title><link>http://www.blogjava.net/zpuser/archive/2007/08/31/141647.html</link><dc:creator>acooly</dc:creator><author>acooly</author><pubDate>Fri, 31 Aug 2007 02:45:00 GMT</pubDate><guid>http://www.blogjava.net/zpuser/archive/2007/08/31/141647.html</guid><wfw:comment>http://www.blogjava.net/zpuser/comments/141647.html</wfw:comment><comments>http://www.blogjava.net/zpuser/archive/2007/08/31/141647.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/zpuser/comments/commentRss/141647.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/zpuser/services/trackbacks/141647.html</trackback:ping><description><![CDATA[Error convertoring HTML to XHTML: System.ArgumentException: Cannot have ']]&gt;' inside an XML CDATA block.
   at System.Xml.XmlTextWriter.WriteCData(String text)
   at System.Xml.XmlWriter.WriteNode(XmlReader reader, Boolean defattr)
   at FreeTextBoxControls.Support.Formatter.HtmlToXhtml(String input)<img src ="http://www.blogjava.net/zpuser/aggbug/141647.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/zpuser/" target="_blank">acooly</a> 2007-08-31 10:45 <a href="http://www.blogjava.net/zpuser/archive/2007/08/31/141647.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>基于角色的访问控制RBAC</title><link>http://www.blogjava.net/zpuser/archive/2007/07/04/128062.html</link><dc:creator>acooly</dc:creator><author>acooly</author><pubDate>Wed, 04 Jul 2007 04:10:00 GMT</pubDate><guid>http://www.blogjava.net/zpuser/archive/2007/07/04/128062.html</guid><wfw:comment>http://www.blogjava.net/zpuser/comments/128062.html</wfw:comment><comments>http://www.blogjava.net/zpuser/archive/2007/07/04/128062.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/zpuser/comments/commentRss/128062.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/zpuser/services/trackbacks/128062.html</trackback:ping><description><![CDATA[1.概述 <br /><br />　　最近，随着电子商务和电子政务的发展，网络安全已成为研发的重点和热点。信息的完整性、机密性、身份鉴别和不可否认性构成了信息安全的四要
素。非对称加密算法从理论和实践上都可以保证身份的有效性和不可否认性，而要保证软件系统、数据库和信息网络的完整性、和机密性，至今还没有一个行之有效
的解决方案。如公司资源的讹误，信息的未授权泄漏或者失窃，以及被非法篡改都是因为没有保证信息的机密性和完整性而引起的。它们不仅破坏了组织的操作，并
有可能涉及到金融，法律，人员安全，个人隐私和国家机密方面，而造成重大的损失。 <br /><br />　　当今最著名的美国计算机安全标准是可信计算机系统评估标准（TCSEC）。其中一个内容就是要阻止未被授权而浏览机密信息。TCSEC规定了
两个访问控制类型：自主访问控制（DAC）和强制访问控制（MAC）。DAC是指主体可以自主地将访问权限或者访问权限的某个子集授予其他主体。主要是某
些用户（特定客体的用户或具有指定特权的用户）规定别的用户能以怎样的方式访问客体。它主要满足商业和政府的安全需要，以及单级军事应用。但是由于它的控
制是自主的，所以也可能会因为权限的传递而泄漏信息。另外，如果合法用户可以任意运行一个程序来修改他拥有的文件存取控制信息，而操作系统无法区分这种修
改是用户自己的操作，还是恶意程序的非法操作，解决办法就是通过强加一些不可逾越的访问限制。因此，又提出了一种更强有力的访问控制手段，即强制访问控制
（MAC），但是它主要用于多级安全军事应用，很少用于其他方面。现今人们在MAC基础上提出基于角色的访问控制（RBAC），它是一种强制访问控制形
式，但它不是基于多级安全需求。其策略是根据用户在组织内部的角色制定的。用户不能任意的将访问权限传递给其他用户。这是RBAC和DAC之间最基本的不
同。 <br /><br />　　基于角色访问控制（RBAC）模型是目前国际上流行的先进的安全访问控制方法。它通过分配和取消角色来完成用户权限的授予和取消，并且提供角
色分配规则。安全管理人员根据需要定义各种角色，并设置合适的访问权限，而用户根据其责任和资历再被指派为不同的角色。这样，整个访问控制过程就分成两个
部分，即访问权限与角色相关联，角色再与用户关联，从而实现了用户与访问权限的逻辑分离。 <br /><br />　　由于实现了用户与访问权限的逻辑分离，基于角色的策略极大的方便了权限管理。例如，如果一个用户的职位发生变化，只要将用户当前的角色去掉，
加入代表新职务或新任务的角色即可。研究表明，角色/权限之间的变化比角色/用户关系之间的变化相对要慢得多，并且给用户分配角色不需要很多技术，可以由
行政管理人员来执行，而给角色配置权限的工作比较复杂，需要一定的技术，可以由专门的技术人员来承担，但是不给他们给用户分配角色的权限，这与现实中的情
况正好一致。 <br /><br />　　基于角色访问控制可以很好的描述角色层次关系，实现最小特权原则和职责分离原则。 <br /><br />　　2.RBAC的正式定义 <br /><br />　　基于角色访问控制（RBAC）的定义已经在第十五届国际计算机安全会议上以集合的形式给出。定义如下： <br /><br />　　对于每一主体，激活角色是当前使用的主体： <br /><br />　　AR（s：subject）={主体s的激活角色} <br /><br />　　每一主体可被授权扮演一个或更多角色： <br /><br />　　RA（s：subject）={主体s的授权角色} <br /><br />　　每一角色可被授权执行一个或更多事务： <br /><br />　　TA（r：role）={授权给角色r的事务} <br /><br />　　主体可以执行事务。如果主体s可以在当前时间执行事务t，则预测exec（s，t）是真，否则为假： <br /><br />　　exec(s: subject, t: tran) =true, 如果主体s可以执行事务t。 <br /><br />　　执行过程中的三个基本规则： <br /><br />　　2.1 角色分配：仅当主体选择或被赋予一个角色，主体才能执行一个事务。 <br /><br />　　　<img src="http://www.stcore.com/imgfiles/2003.4.11.13.14.38.a.gif" /><br /><br />　　身份证明和鉴别过程（例如登录）不是一个事务。其他用户的所有在系统上的活动都可通过事务处理。因此要求所有激活用户具有某个激活角色。 <br /><br />　　2.2 角色授权：主体的激活角色必须是被授权的：<br />同上面的（1）一起，规则保证用户只能接收他们授予的角色。 <br /><br />　　2.3 事务授权：仅当事务被授权给主体激活角色时，主体才能执行该事务。 <br /><br />　　　<img src="http://www.stcore.com/imgfiles/2003.4.11.13.15.14.c.gif" /><br /><br />　　同（1）和（2）一起，本规则保证用户只可执行授权给他们的事务。注意，因为条件是“仅当（only
if）”，本规则允许事务执行的出现附加限制的可能性。即，规则不保证一个事务只是因为它在TA(AR(s))中就是可执行的，TA(AR(s))是由主
体激活角色执行的潜在事务集合。例如，一个主管角色的实习生可被赋予“主管”角色，但是在运用他/她用户角色时有限制，即对一主管可正常访问的子集，实习
生可能受到限制。 <br /><br />　　上文中，“事务”的定义是变换过程（transformation
procedure）加上一个由变换过程访问的数据项集。因为数据访问已被构建到事务中，所以上面规则的访问控制不要求对用户访问数据目标的权利或变换程
序访问数据项的权利作任何检查。由于在设计阶段将操作和数据绑定为一个事务，所以存在安全性问题，例如此时的在保险查询事务中提出的个人隐私的问题。 <br /><br />　　当规则中“事务”只指变换程序时，需要重新定义“事务”的含义，即不包括对目标的绑定。若要实施方式控制则需要第四个规则，即在模型中用户通
过事务程序访问目标。例如，利用事务（重新定义为变换程序），第四个规则可被定义为对象访问函数access(r, I, o, x)， <br /><br />　　<img src="http://www.stcore.com/imgfiles/2003.4.11.13.15.24.d.gif" /><br /><br />　　它表明了是否允许角色r的主体利用事务t以x的方式来访问对象o，其中x是已经缩小的模式的集合。例如读，写，附加。 <br /><br />　　第四项规则可适用于医院配置。一位医生可被提供读/写药方的访问控制，而医院的药剂师可能只具有读的访问权力。（单独调用前三个规则，将事务过程t与t能访问的数据对象绑定在一块，并且只控制对事务的访问）。我们可以使用第四个规则替换，更有益于满足机密性的要求。 <br /><br />　　RBAC的另一个用途是支持完整性。完整性以几种不同的方式定义，但完整性的一个方面是要求数据和程序只能由授权用户以被授权的方式修改。这看起来对于很多真实的系统是一合理的安全目标，同时RBAC应适用于这样的系统。 <br /><br />　　一般来说，决定数据是否只以授权的方式修改的问题与修改事务是同样复杂的。由于这个原因，实际的方法是事务直接与另一事务合并。要求系统通过
规则（4）中的访问函数控制事务程序对对象的访问，但是要取得完整性的同时需要极大的系统开销。因此，在RBAC中包含事务对对象的访问控制函数将在一些
应用集中是有用的，但并不是所有的应用。 <br /><br />　　3.最小特权策略 <br /><br />　　最小特权原则对于满足完整性目标是非常重要的。最小特权原则要求用户只具有执行一项工作所必需的权限。要保证最小特权要求验证用户的工作是什
么，要确定执行该项工作所要求的权限最小集合，并限制用户的权限域。若拒绝了不是主体职责的事务，则那些被拒绝的权限就不能绕过阻止安全性策略。尽管最小
特权包含当前存在于TCSEC的内容当中，但仍限制系统管理员的权限。通过使用RBAC，很容易满足一般系统的用户执行最小权限。 <br /><br />　　4.职责分离 <br /><br />　　RBAC机制可被系统管理员用于执行职责分离的策略。职责分离对于反欺诈行为是非常有效的。它是在真实系统中最重要的想法。 <br /><br />　　职责分离或者是静态的，或者是动态的。符合静态职责分离要求职能由个人角色的分配和事务角色的分配决定的。最难的是动态职责分配，其中符合动态职责分离的职能在系统操作期间决定。动态职责分离目的是允许操作更灵活。 <br /><br />　　根据角色分配访问权利在定义职责分离上也是有帮助的，它由系统执行。 <br /><br />　　5.结论 <br /><br />　　虽然商业和政府组织中很多终端用户能够访问信息，但他们都不“拥有”信息。而这些组织机构恰恰是实际系统对象的“拥有者”，并且自主访问控制是不可能适合的。基于角色访问控制（RBAC）是一个非自主访问控制机制，它允许促进组织具体安全策略的中央管理。<br />访问控制决策通常基于角色，个人用户采取的角色作为组织的组成。一个角色规定了一个事务集合，即用户或用户集合可在组织内执行。RBAC提供命名和描述个人和权利之间的关系的方法，提供很多商业和政府组织需要的安全处理方法。 <br /><br />　　本文提到的基于角色访问控制（RBAC）的定义，已经在第十五届国际计算机安全会议上以集合的形式给出。本文的目的是让更多热爱网络安全的朋友了解RBAC，使这一新型的访问控制方案得到更多的应用。 <br /><br /><img src ="http://www.blogjava.net/zpuser/aggbug/128062.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/zpuser/" target="_blank">acooly</a> 2007-07-04 12:10 <a href="http://www.blogjava.net/zpuser/archive/2007/07/04/128062.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>NFC</title><link>http://www.blogjava.net/zpuser/archive/2007/06/28/126942.html</link><dc:creator>acooly</dc:creator><author>acooly</author><pubDate>Thu, 28 Jun 2007 15:31:00 GMT</pubDate><guid>http://www.blogjava.net/zpuser/archive/2007/06/28/126942.html</guid><wfw:comment>http://www.blogjava.net/zpuser/comments/126942.html</wfw:comment><comments>http://www.blogjava.net/zpuser/archive/2007/06/28/126942.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/zpuser/comments/commentRss/126942.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/zpuser/services/trackbacks/126942.html</trackback:ping><description><![CDATA[
		<div>NFC(Near Field Communication, 近距离通讯技术)是脱胎于无线设备间的一种“非接触式射频识别”(RFID)及互联技术，为所有消费性电子产品提供了一个极为便利的通讯方式。</div>
		<div> </div>
		<div>
				<b>1</b>
				<b>．技术优势</b>
		</div>
		<div>NFC在单一芯片上结合了感应式读卡器，感应式卡片和点对点的功能。在数厘米（通常是15厘米以内）距离之间于13.56MHz频率范围内运
作，通过射频信号自动识别目标对象并获取相关数据，识别工作无须人工干预，任意两个设备（如移动电话、蓝牙设备、ＷｉＦｉ设备）接近而不需要线缆接插，就
可以实现相互间的通信，可以满足任何两个无线设备间的信息交换、内容访问、服务交换。此外，拥有 NFC
功能的消费电子装置可以轻易地交换或储存个人资料，其中包括各种讯息、照片、MP3等。为消费者实现使用简便、免安装设定、现场立即联机、智能型门控等功
能，完全符合现代消费者的需求。</div>
		<div> </div>
		<div>
				<b>2</b>
				<b>．应用类型</b>
		</div>
		<div>NFC 应用可区分为四个基本类型：</div>
		<div>
				<b>Touch and Go</b>
		</div>
		<div>这类应用就像门禁管制或车票及门票等，使用者只需携带储存着票证或门控代码的装置靠近读取装置即可，它还可做为简易的数据撷取应用，例如从海报上的智能型标签直接读取网址。 </div>
		<div> </div>
		<div>
				<b>Touch and Confirm</b>
		</div>
		<div>这类应用主要涵盖行动付费机制，通常使用者必须输入密码，以确认交易行为，有时则只要直接进行交易即可。 </div>
		<div> </div>
		<div>
				<b>Touch and Connect</b>
		</div>
		<div>将两个内建 NFC 的装置相连接，以进行点对点数据传输，例如下载音乐、交换影像与同步处理通讯簿等。 </div>
		<div> </div>
		<div>
				<b>Touch and Explore</b>
		</div>
		<div>NFC 装置所提供的功能极为丰富，消费者可以自行