[Version 2.6 update: you can do this much easier using the new RSA_EncodeMsg function.
See RSA Techniques.]
There are three VB6/VBA modules.
rsaes_oaep_Encrypt and rsaes_oaep_Decrypt.
A test example is given that shows how to call the encryption functions
after generating a unique seed using the
RNG_Bytes function.
The module also includes the common code for the MGF1 function and some useful
utilities we use for handling byte arrays: AppendBytes(),
BytesLength(), XorBytes(), BytesAreEqual()
and ISOSP4().
It also includes the readPrivateKeyInfo() function which we use to read the
unencrypted private key files we've extracted from the test vector file.
We do this for convenience. In practice, we'd only be keeping and using encrypted private key files.
All these example functions carry out their encryption and decryption operations using byte arrays
and output the results to the immediate window using Debug.Print.
It all looks pretty boring to the observer who isn't familiar with hexadecimal notation and the
details of how PKCS#1 is meant to work.
We've left in all the Debug statements so you can see what's happening.
Errors are just handled with MsgBox statements for simplicity.
You are welcome to alter the code to suit your own error-handling in your own applications.
These three Visual Basic modules can be downloaded in zipped format
rsaes-oaep-vbcode.zip (26 kB).
The public and private RSA key files extracted from the test vector data are in
rsaes-oaep-keys.zip (13 kB).
Note that the private keys are stored in unencrypted private key info format,
except for the rsa1024epk.bin file which has the password "password".
To read these unencrypted files, see the function readPrivateKeyInfo() referred to in (2) above.
To encrypt a private key info file, use the function encryptPrivateKeyInfo() given in (1) above.
You will need to include in your project the module basCrPKI and install the
CryptoSys PKI Toolkit
available from http://www.cryptosys.net/pki/.
If you want to see the Perl script we used to extract all this stuff, please download extract-vect.zip (3 kB).
Comments? Found a mistake? Please let us know.
This page last updated: 3 September 2005