整個演算法的流程是:
接收方先同時生成公鑰和私鑰, 再把公鑰傳遞給傳送方, 傳送方收到公鑰後, 用此公鑰將自己的明文加密, 然後將加密後的密文傳遞給接收方, 接收方用自己的私鑰解密得到明文. 以下是演示這個過程的示例**:
//待加密的明文
string
origintext="
hello";
//公鑰
string
publickey;
system.security.cryptography.rsacryptoserviceprovider rsareceive
=newsystem.security.cryptography.rsacryptoserviceprovider();
system.security.cryptography.rsacryptoserviceprovider rsasend
=newsystem.security.cryptography.rsacryptoserviceprovider();
//接收方先生成公鑰, 並將此公鑰公開
//引數false 表示只生成公鑰, 如果為true, 則同時生成公鑰和私鑰.
publickey
=rsareceive.toxmlstring(
false
);//傳送方接收公鑰, 並用此公鑰加密資料
rsasend.fromxmlstring(publickey);
//傳送方執行加密.
//第二個引數指示是否使用oaep, 如果使用, 則程式必須執行在windows xp 及以上版本的
//系統中. 無論true 或false, 解密時必須跟加密時的選擇相同.
byte
cryp
=rsasend.encrypt(system.text.encoding.utf8.getbytes(origintext),
false
);//接收方用自己的私鑰解密
byte
b_origintext
=rsareceive.decrypt(cryp,
false
);
用ajax技術實現的乙個小例子
早就聽說過ajax,不過想著是網頁上的技術,一直沒有研究過。最近由於工作需要,寫web頁面,想實現區域性重新整理頁面的效果,同時進行一些後台操作,比如運算元據庫。找同事幫忙實現了一下,今天閒來無事,自己研究了一下,還挺簡單就能實現我想要的效果。先說下概念吧,都是從網上搜的,理解了這些,寫 就簡單了。...
乙個可逆加密的例子
page language c enableviewstate true codebehind encryptstring.aspx.cs autoeventwireup false inherits emeng.exam.encryptstring using system using syste...
乙個可逆加密的例子
下面的這個例子實現了乙個可逆加密的例子功能。很簡單,這裡就不多解釋了。如下 encstring.aspx page language vb autoeventwireup false codebehind encstring.aspx.vb inherits aspxweb.encstring en...