-----------------------------------------------------------

New Message on BDOTNET

-----------------------------------------------------------
From: BanupriyaVelmurugan
Message 11 in Discussion

Hi,   Thanks for all your replies...   But my actual requirement is to pass the 
combined key that is generated in one page during encryption to another page 
for decryption...For this I thought of using a seperate calss and stroring the 
key value there and fetching again....   Here is a sample that I created for 
cryptography...RSA algorithm....ASP.NET (VB.NET)     Please help me with the 
code if possible....   The Front End HTML Code Used in first page 
(WebForm1.aspx) is: <form name="Form1" action="./WebForm2.aspx" method="post">
<table width="500" cellpadding="0" cellspacing="0" border="0">
 <tr>
  <td>User ID</td>
  <td><input type="text" name="txtUID"></td>
 </tr>
 <tr>
  <td>Password</td>
  <td><input type="text" name="txtPwd"></td>
 </tr>
 <tr>
  <td colspan="2">&nbsp;</td>
 </tr>
 <tr>
  <td colspan="2" align="center"><input type="submit" name="btnSubmit" 
value="Login"></td>
 </tr>
</table>
</form>   And the Code behind vb.net of second page (WebForm2.aspx) is: 
Protected DecryptedStrAsString As String
Protected EncryptedStrAsString As String
 Private Sub Page_Load(ByVal sender As System.Object, ByVal e As 
System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here
        Dim cspParam As CspParameters
        cspParam = New CspParameters
        cspParam.Flags = CspProviderFlags.UseMachineKeyStore         Dim RSA As 
RSACryptoServiceProvider = New RSACryptoServiceProvider
        Dim publicKey As String = RSA.ToXmlString(False) ' gets the public key
        Dim privateKey As String = RSA.ToXmlString(True) ' gets the private key 
        Response.Write(privateKey)
        'Encrypt the UserID
        Dim strUserID As String = Request.Form("txtUID")
        Dim RSA2 As RSACryptoServiceProvider = New 
RSACryptoServiceProvider(cspParam)
        RSA2.FromXmlString(privateKey)
        Dim EncryptedStrAsByt() As Byte = 
RSA2.Encrypt(System.Text.Encoding.Unicode.GetBytes(strUserID), False)
        EncryptedStrAsString = 
System.Text.Encoding.Unicode.GetString(EncryptedStrAsByt)         'Decrypt the 
UserID
        Dim RSA3 As RSACryptoServiceProvider = New 
RSACryptoServiceProvider(cspParam)
        RSA3.FromXmlString(publicKey)
        Dim DecryptedStrAsByt() As Byte = 
RSA3.Decrypt(System.Text.Encoding.Unicode.GetBytes(EncryptedStrAsString), False)
        DecryptedStrAsString = 
System.Text.Encoding.Unicode.GetString(DecryptedStrAsByt)
End Sub   Note: We can also use the following instead of ToXMLString(...) and 
FromXMLString(...)   Dim completeParams As RSAParameters = 
RSA.ExportParameters(True)
Dim publicParams As RSAParameters = RSA.ExportParameters(False)   
RSA3.ImportParameters(publicParams)
RSA3.ImportParameters(completeParams)   Here I did both the encryption and 
decryption on the same page.   But I need to export the publicKey generated in 
WebForm2.aspx to WebForm3.aspx and then wants to decrypt the data.   Is it 
possible to do so?   If so...Please help me providing some sample codes...   
Thanks & Regards Banu

-----------------------------------------------------------

To stop getting this e-mail, or change how often it arrives, go to your E-mail 
Settings.
http://groups.msn.com/bdotnet/_emailsettings.msnw

Need help? If you've forgotten your password, please go to Passport Member 
Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help

For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact

If you do not want to receive future e-mail from this MSN group, or if you 
received this message by mistake, please click the "Remove" link below. On the 
pre-addressed e-mail message that opens, simply click "Send". Your e-mail 
address will be deleted from this group's mailing list.
mailto:[EMAIL PROTECTED]

Reply via email to