NCrypto Encryption & Decryption

S

sushant.bhatia

Hi All.
I'm using the NCrypto dll for RSA Encryption/Decryption
(http://sourceforge.net/projects/ncrypto/). My encryption code in .Net
is pretty simple. The dataToEncrypt length is 1024. The returned data
is 1161 in length.

public static byte[] EncryptRSA(string certFilePublic, byte[]
dataToEncrypt)
{
RSAParameters rsaParams = GetRSAPubKey(certFilePublic);

byte[] decryptedData = null;
try
{
decryptedData =
NCrypto.Security.Cryptography.CryptoHelper.Encrypt(dataToEncrypt,
rsaParams, false);
return decryptedData;
}
catch (Exception eer)
{
System.Windows.Forms.MessageBox.Show(eer.ToString());
return null;
}
}


The problem is when I try to decrypt I get a "System.ArgumentOutOfRange
Exception: Data length must be a multiple of 128. Parameter name:
cipherText".
The problem is that the encrypt function creates data that is 1161
bytes long which isn't a multiple of 128.

I've tried changing the data size going into the decrypt function but
the data returned is always a multiple of 129 and not 128.

Please HELP! I'm so stuck as to what to do. :-(
 
S

Sushant Bhatia

I managed to do this with Michel Gallants articles. But I feel he is
working at a much deeper level than most of us newbies can comprehend.
So, I will write an article that will "DUMB DOWN" the following and
show you exactly how to do:-

-RSA Encryption/Decryption
-Digital Certificate (.cer) public key parsing to get RSAParameters
-PKCS#12 (.pfx) private key parsing to get RSAParameters
-Symmetric Encryption/Decryption

Give me a few days for this. I have finals and school projects at the
moment so need to take care of those first. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top