exception - cryptopp plaintext fixed length limit -


When I pass initialText86 , the code below should work when I Passed initialText87 fails to create this StringSource SS1 , and we complete the exception Invalid argument !

How can I encode string with length 87?

  #include & lt; String & gt; # Include & lt; New & gt; using namespace std; # Include & lt; ../pub/cryptopp/rsa.h & gt; # Include & lt; ../pub / cryptopp / osrng.h & gt; # Include & lt; ../pub / cryptopp / oaep.h & gt; # Include & lt; ../pub / cryptopp / sha.h & gt; Using Namespace Crypopp; AutoSeededRandomPool & amp; Rng_get () {static autoshddrackpuff defRng; DefRng return; } String rsa_encode (const String & amp; plain, constant RSA ::; PublicKey & amp pubKey) {RSAES_OAEP_SHA_Encryptor rsaEnc (pubKey); String ciphertext; StringSource SS1 (reinterpret_cast & LT; constant byte * & gt; (plainText.c_str ()), plainText.size (), true, new PK_EncryptorFilter (rng_get (), rsaEnc, New StringSink (zero)) // PK_EncryptorFilter); // Return string source (cipher text); } String rsa_decode (Const string and ciphertext, Const RSA :: Nijiki and Guptki) (RSAES_OAEP_SHA_Decryptor rsaDec (secretKey); string plain text; StringSource SS2 (reinterpret_cast & LT; constant byte * & gt; (cipherText.c_str ()), CipherTextksize (), true, new PK_DecryptorFilter (Rng_get (), RsaDec, new StringSink (plain)) // PK_DecryptorFilter); // string source-back move (plain text);} static command Akar_ti Kilanl = 1024; RSA: : Private _secretKey; RSA :: Public Key_books; Bool Test (Const String and Initial Texts) K) {auto ciphertext = Arsaaan code (initial text _ Pbkike); Auto Plain text = Arsadeeded (ciphertext, _secretKey); return plain text == initial text;} Int main () {_secretKey.GenerateRandomWithKeySize (rng_get () , KeyLength); New (& amp; _pubKey) RSA :: Public Key (_secretKey); String Initial Period 87 = "111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"; String initialText86 = "11111111111111111111111111111111111111111111111111111111111111111111111111111111111111"; Auto testSecurity = Examination (preliminary chapter 87); Insist (TestRsult); Is the result of the return exam? 0: -1; }  

RSA can be encrypted using data which primarily Size is determined by the key that you are using the maximum length so you are using OAEP:

  keyLength - 2 - 2 * hashLength  

Where is the length of RSA modulus in keyLength bytes. You are using a 1024 bit key:

  keyLength = 1024/8 = 128  

And since you have been using OAEP with SHA-1 It is

  hashLength = 20  

so you can encrypt the maximum:

  128 - 2 - 2 * 20 = 86  

What does your example show?

To encrypt more data, you can use a large RSA key, but RSA is actually used to encrypt large amounts of data. , then usually encrypted key randomly generated for a hybrid cryptosystem where RSA instead of a symmetric algorithm like AES, and then used to encrypt symmetric algorithm real The data is used as part of the so avoid the length limit attached to the RSA.


Comments