This project is read-only.

The right way to encrypt an array of lenght 1500

Dec 21, 2014 at 8:57 PM
I'm trying to encrypt a string whose lenght is about 1500 using the method CryptographicEngine.Encrypt. I am getting an exception that my "inputArray" is too big. I plan to divide the input array into blocks, but can not find a variable that determines the size of the block.

Is there such a variable ?
Is this the right way to solve the problem ?
Whether this issue should be resolved differently with 'PCLCrypto' ?
Dec 21, 2014 at 10:52 PM
CryptographicEngine.Encrypt is the right method to call. But it sounds like you're passing in an inappropriate key as the first argument to that method. I'm guessing you've created an asymmetric key and are using that. But asymmetric keys are only appropriate for encrypting symmetric keys. Since you're actually encrypting a 1500 character string, you should encrypt that with a symmetric key instead.

So if you create a symmetric key, then encrypt your 1500 character string with that, it should work.

If you want to use asymmetric encryption, as a second step you can then encrypt the symmetric key with your asymmetric key. But just note the ultimate user data itself is always encrypted symmetrically. This isn't just an PCLCrypto usage pattern: it's common cryptography.
Marked as answer by LucasKuzma on 12/25/2014 at 5:18 AM
Dec 22, 2014 at 10:08 PM
Thanks for your reply.
After the creation of a symmetric key can be exported using the method ICryptograficKey.Export ?
When I try to do it I get an exception "Not Implemented exception", it is a good way to keep a symmetric key for reuse ?
Dec 23, 2014 at 3:39 PM
You create a symmetric key by passing in the key material when you create it. So you don't have to export it. Just keep your key material around to create it again later.
Marked as answer by LucasKuzma on 12/25/2014 at 5:18 AM
Dec 25, 2014 at 1:17 PM
Thank for your help, your hints were very helpfull. Everything is clear now.