Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. RSACryptoServiceProvider

RSACryptoServiceProvider

Scheduled Pinned Locked Moved ASP.NET
csharpasp-netvisual-studiodesignwindows-admin
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    guroo13
    wrote on last edited by
    #1

    Hi, I am trying to use RSACryptoServiceProvider in my ASP.NET application to access keys from a MachineKeyStore on my computer, running windows xp and IIS 5. I created machinekeystore like following in Visual Studio 2005 Command Prompt: aspnet_regiis -pc "CustomKeys" -exp (command was successful) Then I executed following command because I am impersonating my web application with a non-default user: aspnet_regiis -pa "CustomKeys" "domain\auserforapplication" (command was successful) Then I worte the following code: public partial class Examples_EncryptionExample : System.Web.UI.Page { CspParameters CspParam; string publicXmlString = string.Empty; string privateXmlString = string.Empty; protected void Page_Load(object sender, EventArgs e) { try { byte [] encrypted; string decrypted; UnicodeEncoding ByteConverter = new UnicodeEncoding(); encrypted = EncrptData("data to encrypt"); Response.Write(System.Text.Encoding.Unicode.GetString(encrypted)); decrypted = DecryptData(encrypted); Response.Write(decrypted); } catch (Exception ex) { } } public string DecryptData(byte [] data) { RSACryptoServiceProvider RsaCsp; byte[] decryptedData; RsaCsp = new RSACryptoServiceProvider(); RsaCsp.FromXmlString(privateXmlString); decryptedData = RsaCsp.Decrypt(data, false); return System.Text.Encoding.Unicode.GetString(decryptedData); } public byte [] EncrptData(string data) { RSACryptoServiceProvider RsaCsp; RSACryptoServiceProvider RsaCsp2; UnicodeEncoding ByteConverter = new UnicodeEncoding(); CspParam = new CspParameters(); CspParam.KeyContainerName = "CustomKeys"; CspParam.Flags = CspProviderFlags.UseMachineKeyStore; byte[] encryptedData = ByteConverter.GetBytes(data); RsaCsp = new RSACryptoServiceProvider(CspParam); //Getting public key publicXmlString = RsaCsp.ToXmlString(false); //Getting private key privateXmlString = RsaCsp.ToXmlString(true); RsaCsp2 = new RSACryptoServiceProvider(); RsaCsp2.FromXmlString(publicXmlString); encryptedData = RsaCsp2.Encrypt(System.Text.Encoding.Unicode.GetBytes(data), false); return encryptedData; } } The problem over here is that when ever I try t

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups