13

I want to provide my application with simple licensing mechanism based on RSA algorithm.

Are there any free RSA libraries?

4 Answers 4

34

Just use the javax.crypto and java.security packages. It's in the Java standard platform.

KeyPair keys = KeyPairGenerator.getInstance("RSA").generateKeyPair();
Cipher cipher = Cipher.getInstance("RSA");
cipher.init(Cipher.ENCRYPT_MODE, keys.getPublic());
byte[] encrypted = cipher.doFinal(rawData);

Links for the official documentation:

Sign up to request clarification or add additional context in comments.

Comments

7

Yes, check out BouncyCastle.

4 Comments

Why would you use BouncyCastle instead of the cryptography functionality in the standard API?
jarnbjo: Not sure, but I was just answering the question. However, I did upvote kdgregory, because I do think that's probably the best way to do it. Though IIRC (and I probably don't) there was a time when crypto wasn't built-in to the regular Java download.
@silky - iirc it came in around 1.4; I just started using it recently ... btw, you upvoted me too soon (but thanks): I had copied one of my learning examples, and included my own method in it :-)
silky: JCE (Java Cryptography Extension) is available as a separate download for Java 1.2 and 1.3 and has been part of the standard API since 1.4, so it has been around for some 10 years. BouncyCastle can very well be used as an additional JCE provider for algorithms not supported by the default VM security providers, but there's no need to add a dependency on a 3rd party lib for common algorithms like RSA.
1

If for some reason you don't want to use what is build into the platform, then Keyczar is generally the most suggested / best solution for any other sort of cryptographic needs.

2 Comments

IMO Bouncycastle is much better known, far more complete and mature, and more frequently recommended.
That does not necessascarily mean it's better @JamesKPolk
0

I recently used the open source framework Jasypt http://www.jasypt.org/index.html. This framework also work very well together with Spring and Hibernate

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.