467,915 Members | 1,541 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,915 developers. It's quick & easy.

NCrypto Encryption & Decryption

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. :-(

Nov 19 '05 #1
  • viewed: 2301
Share:
2 Replies
please try also another Crypto DLL:
www.aspsimply.com/vbnet/protool.aspx


<su************@gmail.com> wrote in message
news:11**********************@l41g2000cwc.googlegr oups.com...
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. :-(

Nov 19 '05 #2
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. :-)

Nov 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by D. Alvarado | last post: by
1 post views Thread by Jase H | last post: by
2 posts views Thread by Dave Bailey | last post: by
reply views Thread by sushant.bhatia | last post: by
3 posts views Thread by =?Utf-8?B?TG9yZW4=?= | last post: by
13 posts views Thread by Tom Andrecht | last post: by
9 posts views Thread by Betikci Boris | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.