2

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

kal
  • 305
  • 6
  • 12
  • 1
    Do you absolutely need to use Bouncy castle? because I'd recommend GNU Crypto, is more easy to learn and manage, and there's lots of tutorials on Google – Alvin Baena Oct 29 '11 at 18:31
  • You're required to use Bouncy Castle? Given your requirements standard Java libs should work as well. Please add the 'homework' tag. – home Oct 29 '11 at 18:32
  • No bouncy castle isnt a requirement. Is GNU Crypto for java? Java is sort of required because my team members dont know C/C++ or scripting languages like Python. Also thanks for the reply. Also I added the homework tag, my apologies. – kal Oct 29 '11 at 18:32
  • 1
    Did you have a look at [this](http://download.oracle.com/javase/tutorial/security/apisign/step2.html). Maybe this is all you need... – home Oct 29 '11 at 18:37
  • @home Thank you. This looks more comfortable to work with for a beginner like me. I greatly appreciate your help. – kal Oct 29 '11 at 18:45

1 Answers1

2

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.

Paŭlo Ebermann
  • 73,284
  • 20
  • 146
  • 210
  • Thank you, this helps me alot. Also I have a question, When I use KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA"); I get a unhandled exception type NoSuchAAlgorithmException – kal Oct 29 '11 at 19:30
  • Read up about exception handling - this is not cryptography specific. You need to either catch these exceptions in a try block, or declare them in a throws clause of your method (and then catch them elsewhere). But read some Java book about this, this comment is to short for an extensive treatment of exception handling. – Paŭlo Ebermann Oct 29 '11 at 19:35