Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: C/C++ programmer doing Java encryption project

  1. #1
    Junior Member
    Join Date
    Jul 2011
    Thanked 0 Times in 0 Posts

    Question C/C++ programmer doing Java encryption project

    Hello all. I've recently started doing a java encryption/decryption project using the crypto and security packages. I have very little experience with java although I do have a lot of experience in C and C++ so I am no stranger to OO programming. Anyway, I have this one line of code which is causing me a problem.

    import java.util.*;
    import DataLog.*;
    import java.security.*;
    import javax.crypto.*;
    import javax.crypto.spec.*;
    public class JCipher {
            private static Cipher jc;
    	public static void main(String[] args)
                      /* Apparently this method does not exist, how should I use the Cipher class? */
                      jc = Cipher.getInstance("DES/CBC/PKCS5Padding");

    Obviously I have more code than that, but it shows the principle.

    Here is the compiler message:
    JCipher.java:79: unreported exception java.security.NoSuchAlgorithmException; must be caught or declared to be thrown
                    jc = Cipher.getInstance("DES/CBC/PKCS5Padding");
    1 error

    I am using JDK 6.27, did they change the interface for accessing the classes, all the info I can find says that I should get an instance rather than doing something like: jc = new Cipher(...);

    The only other idea I have is that my imports are wrong but all the examples I've looked at have the same imports.
    Last edited by Swarvy; July 24th, 2011 at 12:58 AM.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Eastern Florida
    Thanked 2,710 Times in 2,660 Posts

    Default Re: C/C++ programmer doing Java encryption project

    unreported exception java.security.NoSuchAlgorithmException; must be caught or declared to be thrown.
    Put the code inside of a try{}catch(){} block that catches that exception.

Similar Threads

  1. Java Encryption
    By xxcorrosionxx in forum What's Wrong With My Code?
    Replies: 6
    Last Post: February 9th, 2011, 04:12 AM
  2. Java password encryption
    By jmorr212 in forum JDBC & Databases
    Replies: 2
    Last Post: January 29th, 2011, 02:33 AM
  3. Replies: 2
    Last Post: August 1st, 2010, 06:29 AM
  4. Programmer for a Java based game project
    By Takkun in forum Project Collaboration
    Replies: 4
    Last Post: June 14th, 2010, 05:47 PM
  5. Basic Java Encryption
    By BronxBomber in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 9th, 2010, 10:50 PM