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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. RSA public key?

RSA public key?

Scheduled Pinned Locked Moved C#
questiondata-structuressecurityhelplearning
2 Posts 1 Posters 2 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.
  • R Offline
    R Offline
    ravingcoder
    wrote on last edited by
    #1

    Hi, trying to encrypt something using RSAServiceProvide. I have two problems. 1. Bad data when decrypting. (1) In prototype, RSA_Server instance in decrypting side and encrypting side is the same instance. Of course, this will change later. RSAServiceProvider RSA_Server; (2) On encrypting side: RSA_Server = new RSACryptoServiceProvider(); encryptedbuffer = RSA_Server.Encrypt( databuffer, false); NOTE: At first I was suspecting that databuffer is than 5 bytes. But I get same problem after I trimmed databuffer down to one bytes. Anyway, here's quote from MSDN: "The length of the rgb parameter is greater than the maximum allowed length. If the fOAEP parameter is false and the encryption is performed on a computer with the high encryption pack installed, the maximum length of the rgb parameter is 16 bytes. If the high encryption pack is not installed, the maximum length of the rgb parameter is 5 bytes." (3) On decrypting side: plaintext = RSA_Server.Decrypt(encryptedbuffer, false); 2. How can I retrieve private key from RSAParameters instance? I need to "publish" my public key - not the entire RSAParameters. Here's code from MSDN: //Good. PublicKey and "Exponent" are both byte array. byte[] PublicKey = {214,46,220,83,160,73,40,39,201,155,19,202,3,11,191,178,56, 74,90,36,248,103,18,144,170,163,145,87,54,61,34,220,222, 207,137,149,173,14,92,120,206,222,158,28,40,24,30,16,175, 108,128,35,230,118,40,121,113,125,216,130,11,24,90,48,194, 240,105,44,76,34,57,249,228,125,80,38,9,136,29,117,207,139, 168,181,85,137,126,10,126,242,120,247,121,8,100,12,201,171, 38,226,193,180,190,117,177,87,143,242,213,11,44,180,113,93, 106,99,179,68,175,211,164,116,64,148,226,254,172,147}; byte[] Exponent = {1,0,1}; //Create a new instance of RSACryptoServiceProvider. RSACryptoServiceProvider RSA = new RSACryptoServiceProvider(); //Create a new instance of RSAParameters. RSAParameters RSAKeyInfo = new RSAParameters(); //Set RSAKeyInfo to the public key values. RSAKeyInfo.Modulus = PublicKey; <--- OKAY, that's your public key. RSAKeyInfo.Exponent = Exponent; <--- what da? Is this your private key? //Import key parameters into RSA. RSA.ImportParameters(RSAKeyInfo); I need to pass encrypted data + RSA public key to decrypting side. Thanks.

    R 1 Reply Last reply
    0
    • R ravingcoder

      Hi, trying to encrypt something using RSAServiceProvide. I have two problems. 1. Bad data when decrypting. (1) In prototype, RSA_Server instance in decrypting side and encrypting side is the same instance. Of course, this will change later. RSAServiceProvider RSA_Server; (2) On encrypting side: RSA_Server = new RSACryptoServiceProvider(); encryptedbuffer = RSA_Server.Encrypt( databuffer, false); NOTE: At first I was suspecting that databuffer is than 5 bytes. But I get same problem after I trimmed databuffer down to one bytes. Anyway, here's quote from MSDN: "The length of the rgb parameter is greater than the maximum allowed length. If the fOAEP parameter is false and the encryption is performed on a computer with the high encryption pack installed, the maximum length of the rgb parameter is 16 bytes. If the high encryption pack is not installed, the maximum length of the rgb parameter is 5 bytes." (3) On decrypting side: plaintext = RSA_Server.Decrypt(encryptedbuffer, false); 2. How can I retrieve private key from RSAParameters instance? I need to "publish" my public key - not the entire RSAParameters. Here's code from MSDN: //Good. PublicKey and "Exponent" are both byte array. byte[] PublicKey = {214,46,220,83,160,73,40,39,201,155,19,202,3,11,191,178,56, 74,90,36,248,103,18,144,170,163,145,87,54,61,34,220,222, 207,137,149,173,14,92,120,206,222,158,28,40,24,30,16,175, 108,128,35,230,118,40,121,113,125,216,130,11,24,90,48,194, 240,105,44,76,34,57,249,228,125,80,38,9,136,29,117,207,139, 168,181,85,137,126,10,126,242,120,247,121,8,100,12,201,171, 38,226,193,180,190,117,177,87,143,242,213,11,44,180,113,93, 106,99,179,68,175,211,164,116,64,148,226,254,172,147}; byte[] Exponent = {1,0,1}; //Create a new instance of RSACryptoServiceProvider. RSACryptoServiceProvider RSA = new RSACryptoServiceProvider(); //Create a new instance of RSAParameters. RSAParameters RSAKeyInfo = new RSAParameters(); //Set RSAKeyInfo to the public key values. RSAKeyInfo.Modulus = PublicKey; <--- OKAY, that's your public key. RSAKeyInfo.Exponent = Exponent; <--- what da? Is this your private key? //Import key parameters into RSA. RSA.ImportParameters(RSAKeyInfo); I need to pass encrypted data + RSA public key to decrypting side. Thanks.

      R Offline
      R Offline
      ravingcoder
      wrote on last edited by
      #2

      hope someone is reading the thread. QUESTION 3: Is RSAParameters serializable? can I send it via tcp channel as byte array? Thanks.

      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