Java programming resources
I am a Java programmer. I have successfully done some secret key encryption and decryption. I can use the private key to sign a message and verify with the public key, but I still need some coding examples on how to encrypt with the public key and decrypt with the private key or vice versa. Can you recommend any resources on this topic?

    Requires Free Membership to View

    SearchSecurity.com members gain immediate and unlimited access to breaking industry news, virus alerts, new hacker threats, highly focused security newsletters, and more -- all at no cost. Join me on SearchSecurity.com today!

    Michael S. Mimoso, Editorial Director

    By submitting your registration information to SearchSecurity.com you agree to receive email communications from TechTarget and TechTarget partners. We encourage you to read our Privacy Policy which contains important disclosures about how we collect and use your registration and other information. If you reside outside of the United States, by submitting this registration information you consent to having your personal data transferred to and processed in the United States. Your use of SearchSecurity.com is governed by our Terms of Use. You may contact us at webmaster@TechTarget.com.

I find the best place to go for Java code examples is the Sun Developer Network (SDN) run by Sun Microsystems, the developers of Java technology. SDN has two articles, which include the types of example you are after. The first is Cryptography: The Ancient Art of Secret Messages at http://java.sun.com/developer/technicalArticles/Security/Crypto/. The second is Java 2 Cryptography Extension: Encrypting and Decrypting Data at http://java.sun.com/developer/technicalArticles/Security/JCE/. This second article examines the classes in the JCE javax.crypto package and, in particular, the classes that are central to data encryption and decryption, the Cipher and KeyGenerator. They also provide pseudo code segments for an encryption and decryption program. An encryption program uses a secret key to encrypt a text string and a sealed object to wrap the secret key with the recipient's public key. A decryption program receives the encrypted text and wrapped session key over the network, then unwraps the secret key by using its private key and uses the recovered secret key to decrypt the message.

Two other articles that cover code examples are Using RSA encryption with Java by Aviran Mordo at http://www.aviransplace.com/index.php/archives/2004/10/12/using-rsa-encryption-with-java/2/ and Public Key Cryptography 101 Using Java by Richard G. Baldwin: http://www.developer.com/java/ent/article.php/3447491

Finally, if you don't already have it, I suggest looking into the Java Cryptography Extension (JCE)Reference Guide for the Java 2 SDK, Standard Edition, v 1.4 is available at http://java.sun.com/j2se/1.4.2/docs/guide/security/jce/JCERefGuide.html

This was first published in December 2005