Search code examples
javacryptographyrsabouncycastle

Using Bouncy Castle RSA Java


I need help using Bouncy Castle RSA Libraries for a school assignment, but it looks very complicated and I'm trying to learn and need some guidance.

For my assignment I need to just generate a public and private key. Then encrypt a block of message and do timing measurements. Then do the same for decryption.

Could someone point me in the right direction? The Crypto Library is huge and I'm confused on how to go about this.

Thank you very much.

PS: Basically I need to generate the Key Pairs, Execute the encryption and decryption using different key pairs that are randomly generated.

I would appreaciate any guidance, thanks


Solution

  • Normally with Java you would use the Java Cryptography API's, in the java.security.* and javax.crypto.* packages.

    BouncyCastle includes a provider (i.e. an implementation) for this API, but for RSA the one delivered with your JRE should be fine, too. (BouncyCastle additionally also has an own API which does things in other ways.)

    You would need the KeyPair and KeyPairGenerator classes for the key generation, and the Cipher class for the actual encryption and decryption operation.

    For the timing measurement, repeat the encryption/decryption some thousand times to get reliable data.