I’m having some issues using the .Net wrapper of the OpenSSL libraray for computing the RSA Private Key Encryption of a set of bytes.
Currently I read in a .pem file containing the private key I want to use into a BIO object.
public byte[] ComputeRSAEncryption(byte[] dataBlock, BIO privateKey)
{
RSA rsa = RSA.FromPrivateKey(privateKey);
return rsa.PrivateEncryption(dataBlock, RSA.Padding.None);
}
I’m using an RSA key of size 64 bytes and a datablock size of 64 bytes. When the above method is called I get the error:
Data too large for modulus
However if I use a datablock of size 64 bytes where all bytes are set to 0x00 the method works without error.
Is there something I’m missing?
Thanks.
I’ve finally resolved the issue. For anyone else thats interested the Least Significant byte of the datablock must be of value 0x00. By enforcing this condition RSA encryption and decryption works like a charm.