locked
RSA. Encrypt with private key , decrypt with public key RRS feed

  • Question

  •  

    Hello,

    I am trying to use RSACryptoServiceProvider to encrypt a value with the private key ( so i can be the only one to encrypt values ) , and give out a public key so any user can decrypt this value.

    I have read the RSA does support this.Also the implementation of digital signature in RSACryptoServiceProvider actually uses the keys in the above manner,but manually using the private key to encrypt and public to decrypt generates a "bad key" exception.

    Is what i am asking possible using the RSACryptoServiceProvider?If not is there any other way to achieve this kind of behaviour?

    Thank you

     

    Monday, December 26, 2005 1:35 PM

Answers

  • The technique you want to use is signing, not encrypting. You want to prove that the information you sent was not modified. Therefore the information may be sent unencrypted with a sign attached.

    look at RSACryptoServiceProvider.SignData and VerifyData instead.

    Monday, December 26, 2005 5:17 PM
  • Simple answer use

     

    Convert.FromBase64String

     

    instead

    Wednesday, January 4, 2006 9:16 AM

All replies

  • The technique you want to use is signing, not encrypting. You want to prove that the information you sent was not modified. Therefore the information may be sent unencrypted with a sign attached.

    look at RSACryptoServiceProvider.SignData and VerifyData instead.

    Monday, December 26, 2005 5:17 PM
  • Hello Sander,

    Thank you for your reply. You are totally correct.

    Following what you said i have a small problem.After creating the signature i need to send it to the client side, so i convert it to a string :

    Convert.ToBase64String(signature)

    On the client side i convert it back to bytes using :

    Public enc As New UTF8Encoding

    enc.getBytes(signature)

    but the VerifyData return "false".If i run VerifyData directly on the signature prior to converting it to a string it return "True".

    So i guess something goes wrong while converting bytes -> string or string -> bytes.

    Any ideas?

    Akis

    Tuesday, December 27, 2005 1:02 PM
  • Simple answer use

     

    Convert.FromBase64String

     

    instead

    Wednesday, January 4, 2006 9:16 AM