| <div class="vote">0 down vote favorite</div> | <div> <div class="post-text" itemprop="description"> I would like to make a asp.net website using RSACryptoService where in:
I have a few queries as to how to go about it. Firstly, how do i exchange the public key information between the client and the server. This is the code is used: //Code in client.
public partial class LoginPage : System.Web.UI.Page
{
string ServerKeyInfo;
string ClientKeyInfo;
RSACryptoServiceProvider ClientRSA = new RSACryptoServiceProvider();
RSACryptoServiceProvider ServerRSA = new RSACryptoServiceProvider();
WebService.WebService WebServer = new WebService.WebService();
protected void Page_Load(object sender, EventArgs e)
{
this.ClientKeyInfo = ClientRSA.ToXmlString(true);
//Call Webservice passing the client's public key as a parameter and get the public key of the server
this.ServerKeyInfo = WebServer.ExchangeKeyInfo(ClientKeyInfo);
ServerRSA.FromXmlString(ServerKeyInfo);
Label2.Text = ClientRSA.ToXmlString(false);
Label1.Text = ServerRSA.ToXmlString(false);
}
}
//WebService Code
public class WebService : System.Web.Services.WebService {
BackEndCode.BackEndCode Server = new BackEndCode.BackEndCode();
public WebService () {
//Uncomment the following line if using designed components
//InitializeComponent();
}
[WebMethod]
public string ExchangeKeyInfo(string ClientKeyInfo) {
//Call the backend code to exchange the keys
string ServerKeyInfo = Server.ExchangeKeyInfo(ClientKeyInfo);
return ServerKeyInfo;
}
}
//Backend Code in the Server
public class BackEndCode
{
string ServerKeyInfo;
string ClientKeyInfo;
RSACryptoServiceProvider ServerRSA;
RSACryptoServiceProvider ClientRSA;
public BackEndCode()
{
ServerRSA = new RSACryptoServiceProvider();
this.ServerKeyInfo = ServerRSA.ToXmlString(true);
ClientRSA = new RSACryptoServiceProvider();
}
private string opValidationSplChars(string Value)
{
Value = Value.Replace("'", "").Replace(";", "");
return Value;
}
public string ExchangeKeyInfo(string ClientKeyInfo)
{
this.ClientKeyInfo = ClientKeyInfo;
string ServerKeyInfo;
ClientRSA.FromXmlString(ClientKeyInfo);
ServerKeyInfo = ServerRSA.ToXmlString(false);
return ServerKeyInfo;
}
}But when i use it to decrypt i get a bad data Error. </div> </div> |
↧
Encryption and Decryption usinf RSACryptoServiceProvider
↧