well, first, we don't just hand out solutions here. Folk will help you figure out how to do it, but you need to do the heavy lifting.
next...where exactly are you stuck? inserting into the database? creating they keys? Installing the JDK?
Your post is really rather vague, so you are going to have a hard time getting specific help. You need to post specific questions. I'd suggest you check our FAQ on HowToAskQuestionsOnJavaRanch (<--that's a link).
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
That code is flawed both in concept and implementation but primarily in concept.
Concept - the concept of public key cryptography is that private and public keys are generated by someone who is the owner. The private key is kept very very secret and secure so that it can only be used by the owner. The public key does not need to be kept secret or secure and should passed to anyone who needs it to use it. This means that you are unlikely to need to generate an RSA key pair in a Servlet since you would have access to every private key generated in response to a client request and your client would not have access unless you sent it to him. Now you could send it over HTTPS to make it secure but your client would then be able to plausibly deny anything signed by that key since it could equally well be have been signed by you.
Implementation - in your encrypt method this line of code
return a string representation of a reference to an array and does not in any way represent the content of the array. Also, the cipher text is binary and an only safely be converted to text using some form of encoding such as Base64 or ASSCII or ASCII85.
Before going any further you need to spend a significant time learning the fundamental concepts since your current code can at best result in a security flawed implementation.
All of the world's problems can be solved in a garden - Geoff Lawton. Tiny ad:
RavenDB is an Open Source NoSQL Database that’s fully transactional (ACID) across your database