Ask the Expert

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

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

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to: