I need to encrypt a small block of data (16 bytes) using 512 bit RSA public key — quite an easy task for most cryptography libraries known to me, except for MS CSP API, as it seems. Documentation for CryptEncrypt function states that
The Microsoft Enhanced Cryptographic Provider supports direct encryption with RSA public keys and decryption with RSA private keys. The encryption uses PKCS #1 padding.
It didn’t work to me though. Well, my code works and produces encrypted block of data with correct size, but openssl fails to decypher it. It looks much like CryptEncrypt still uses symmetric cypher.
Unfortunately all the examples I’ve found refer to combined cryptography with symmetric cypher, so I don’t have a working example on hands which definitely would make things easier.
Could please anyone point me to such an example or let me know if there are some not that obvious pitfalls I’ve missed?
Thank you.
This sounds like an endianness issue. Microsoft’s CryptEncrypt function returns the ciphertext in little-endian format, while OpenSSL expects its data to be in big-endian format. You’ll need to reverse the encrypted data before passing it to OpenSSL.