Click here to Skip to main content
14,452,963 members
Rate this:
Please Sign up or sign in to vote.
See more:
The data to be decrypted exceeds the maximum for this modulus of 256 bytes.


What I have tried:

Public Function Decrypt(ByVal encryptedText As String, ByVal cert As X509Certificate2) As String
       Try

           Dim privateKey As RSACryptoServiceProvider = CType(cert.PrivateKey, RSACryptoServiceProvider)

           Dim encryptedBytes As Byte() = Convert.FromBase64String(encryptedText)
           Dim decryptedBytes As Byte() = privateKey.Decrypt(encryptedBytes, True)
           Dim decryptedText As String = Encoding.UTF8.GetString(decryptedBytes)
           Return decryptedText

       Catch ex As Exception

       End Try
Posted
Updated 30-Dec-19 13:06pm
v2
Comments
F-ES Sitecore 18-Dec-19 7:02am
   
Google the error message to get an idea what might be wrong, or look for examples of how to use RSACryptoServiceProvider and try and get some sample code working, then adapt to what you are doing.
Rate this:
Please Sign up or sign in to vote.

Solution 1

If you don't understand an error message, Google it: The data to be decrypted exceeds the maximum for this modulus of 256 bytes. - Google Search[^]
Loads of people have met this before, and every link on the first page tells you the same thing: the data is too long to be encrypted with RSA, you need to use AES or Triple-DES
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

You might be interested in this CodeProject article: Swanky Encryption/Decryption in C#[^]
Quote:
can easily handle with my implementation is to split a 50GB file into a series of smaller files with 100MB data each in one go
   
Rate this:
Please Sign up or sign in to vote.

Solution 3

Check out Blowfish might be a better encryption option.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100