Encryption:
<% @ Page Language = "C #" autoeventwireup = "false" %>
<% @ Import namespace = "system. Security. Cryptography" %>
<% @ Import namespace = "system. Io" %>
<% @ Import namespace = "system. Text" %>
<%
String word = request. Params ["word"];
If (WORD = NULL ){
Response. Write ("no password entered !!! ");
Return;
}
Streamreader sr = new streamreader (@ "F:/a.txt", utf8encoding. utf8 );
String readpublickey = Sr. readtoend ();
Sr. Close ();
Rsacryptoserviceprovider crypt = new rsacryptoserviceprovider ();
Utf8encoding ENC = new utf8encoding ();
Byte [] bytes = enc. getbytes (Word );
Crypt. fromxmlstring (readpublickey );
Bytes = crypt. Encrypt (bytes, false );
String encryttext = convert. tobase64string (bytes );
String ABB = server. urlencode (encryttext );
Response. Write (ABB );
Response. Write ("<a href = 'take. aspx? WORD = "+ encryttext +" '> "+ encryttext + @" </a> ");
%>
Decryption:
<% @ Page Language = "C #" autoeventwireup = "false" %>
<% @ Import namespace = "system. Security. Cryptography" %>
<% @ Import namespace = "system. Io" %>
<% @ Import namespace = "system. Text" %>
<%
String word = request. querystring ["word"];
If (WORD = NULL ){
Response. Write ("no password is sent !!! ");
Return;
}
Streamreader sr = new streamreader (@ "F:/B .txt", utf8encoding. utf8 );
String readprivatekey = Sr. readtoend ();
Sr. Close ();
Response. Write ("<br>" + word );
Rsacryptoserviceprovider crypt = new rsacryptoserviceprovider ();
Utf8encoding ENC = new utf8encoding ();
Byte [] bytes = convert. frombase64string (@ word );
Crypt. fromxmlstring (readprivatekey );
Byte [] decryptbyte = crypt. decrypt (bytes, false );
String decrypttext = enc. getstring (decryptbyte );
Response. Write (decrypttext );
%>
The public key is in the.txt file, and the private key is in the B .txt file.
The method for making public and private keys is as follows:
Crypt = new rsacryptoserviceprovider ();
Publickey = crypt. toxmlstring (false); // Public Key
Privatekey = crypt. toxmlstring (true); // Private Key
Crypt. Clear ();
// Write to a text file
Streamwriter one = new streamwriter (@ "F:/a.txt", true, utf8encoding. utf8 );
One. Write (publickey );
Streamwriter two = new streamwriter (@ "F:/B .txt", true, utf8encoding. utf8 );
Two. Write (privatekey );
One. Flush ();
Two. Flush ();
One. Close ();
Two. Close ();
MessageBox. Show ("the public key and secret key are successfully saved! ");