How to use RSACryptoServiceProvider to decrypt a random value? RRS feed

  • Question

  • I need to decrypt a random value, for example:

            Dim rsa As New System.Security.Cryptography.RSACryptoServiceProvider
            Dim random() As Byte = {10, 20, 30, 1, 2, 3, 4, 5}
            Dim decrypted() As Byte = rsa.Decrypt(random, False)

    There is a CryptographicException in line 3. Is there any other way to do so?

    Tuesday, March 19, 2013 6:04 PM


  • You can't decrypt using RSA without having valid encrypted data. RSA uses a 64 byte key and the unexcrypted data is is filled to 64 bytes.  So you will always have encrypted data that is a multiple of 64 bytes.  When decrypting if the key isn't valid or you don't provide encrypted data that is a multiple of 64 bytes you will get an exception.


    • Proposed as answer by Mike FengModerator Wednesday, March 20, 2013 1:39 PM
    • Marked as answer by erbth Wednesday, March 20, 2013 2:10 PM
    Wednesday, March 20, 2013 9:35 AM