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.


>> REGISTER NOW TO START POSTING


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

Results 1 to 16 of 16

Thread: Encryption password by java MD5 and UTF-8

  1. #1
    Junior Member
    Join Date
    Sep 2012
    Location
    Bangladesh
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Encryption password by java MD5 and UTF-8

    Hello, I wanna help from any one. I need java encryption password what will be make by MD5 and UTF-8. I wrote some code when i run this program here show some error. Please check and give me full instruction because i m totally new on java programming.
    import java.io.UnsupportedEncodingException;
    import java.security.MessageDigest;
    import java.security.NoSuchAlgorithmException;
    import sun.misc.BASE64Encoder;
     
    public final class MyPasswordEncrypt {
        public static synchronized String encrypt(String plaintext,
                String algorithm, String encoding) throws Exception {
            MessageDigest msgDigest = null;
            String hashValue = null;
            try {
                msgDigest = MessageDigest.getInstance(algorithm);
                msgDigest.update(plaintext.getBytes(encoding));
                byte rawByte[] = msgDigest.digest();
                hashValue = (new BASE64Encoder()).encode(rawByte);
     
            } catch (NoSuchAlgorithmException e) {
                System.out.println("No Such Algorithm Exists");
            } catch (UnsupportedEncodingException e) {
                System.out.println("The Encoding Is Not Supported");
            }
            return hashValue;
        }
     
        public static void main(String args[]) throws Exception {
            String plainPassword = "SecretPassword";
     
            System.out.println("PlainText\tAlgo\tEncoding\tEncrypted Password");
            System.out.println(plainPassword + "\tSHA\tUTF-8\t"
                    + encrypt("MySecretPassword", "SHA", "UTF-8"));
            System.out.println(plainPassword + "\tSHA-1\tUTF-16\t"
                    + encrypt("MySecretPassword", "SHA-1", "UTF-16"));
            System.out.println(plainPassword + "\tMD5\tUTF-8\t"
                    + encrypt("MySecretPassword", "MD5", "UTF-8"));
            System.out.println(plainPassword + "\tMD5\tUTF-16\t"
                    + encrypt("MySecretPassword", "MD5", "UTF-16"));
     
        }
    }
    Error:
    Main.java:7: class MyPasswordEncrypt is public, should be declared in a file named MyPasswordEncrypt.java
    public final class MyPasswordEncrypt {
    ^
    Main.java:5: warning: sun.misc.BASE64Encoder is Sun proprietary API and may be removed in a future release
    import sun.misc.BASE64Encoder;
    ^
    Main.java:16: warning: sun.misc.BASE64Encoder is Sun proprietary API and may be removed in a future release
    hashValue = (new BASE64Encoder()).encode(rawByte);
    Last edited by jahirul019; September 9th, 2012 at 04:25 PM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Encryption password by java MD5 and UTF-8

    show some error.
    Please post the full text of the error message.

    Also please Edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Nov 2011
    Location
    Aarhus, Denmark
    Posts
    28
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    Well the error seems to indicate that your java file is not named correctly. The other two is just warnings because you are using classes that might be removed in later versions of java.

    /Rolf

  4. #4
    Junior Member
    Join Date
    Sep 2012
    Location
    Bangladesh
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Encryption password by java MD5 and UTF-8

    Please give me below 5 code encryption result
    1. 355735004104438
    2. 355735001013871
    3. 355735004103463
    4. 355735004081859
    5. 355735003961712

    and post for me correct code and run instruction

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Encryption password by java MD5 and UTF-8

    Please explain what your problem is. Post your code and ask any questions you may have about it.
    If you don't understand my answer, don't ignore it, ask a question.

  6. #6
    Junior Member
    Join Date
    Sep 2012
    Location
    Bangladesh
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Encryption password by java MD5 and UTF-8

    Quote Originally Posted by jahirul019 View Post
    Please give me below 5 code encryption result
    1. 355735004104438
    2. 355735001013871
    3. 355735004103463
    4. 355735004081859
    5. 355735003961712

    and post for me correct code and run instruction
    Below warnings show when i run this code
    ====================================

    MyPasswordEncryption.java:6: warning: sun.misc.BASE64Encoder is Sun proprietary API and may be removed in future release
    import sun.misc.BASE64Encoder;

    MyPasswordEncrypt.java:17: warning: sun.misc.BASE64Encoder is Sun proprietary API and may be removed in a future release
    hashValue = <new BASE64Encoder<>>.encode<rawByte>;
    2 warnings

  7. #7
    Junior Member
    Join Date
    Sep 2012
    Location
    Bangladesh
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Encryption password by java MD5 and UTF-8

    Below warnings show when i run this code. please tell me with example, how can i solve this error?

    MyPasswordEncryption.java:6: warning: sun.misc.BASE64Encoder is Sun proprietary API and may be removed in future release
    import sun.misc.BASE64Encoder;

    MyPasswordEncrypt.java:17: warning: sun.misc.BASE64Encoder is Sun proprietary API and may be removed in a future release
    hashValue = <new BASE64Encoder<>>.encode<rawByte>;
    2 warnings

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Encryption password by java MD5 and UTF-8

    If you want to remove the warning, find another class to use.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Sep 2012
    Location
    Bangladesh
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Encryption password by java MD5 and UTF-8

    Quote Originally Posted by Norm View Post
    If you want to remove the warning, find another class to use.
    How can i do it? Please write an example because I am totally new on java

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Encryption password by java MD5 and UTF-8

    Try google.
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Junior Member
    Join Date
    Sep 2012
    Location
    Bangladesh
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Encryption password by java MD5 and UTF-8

    hello, i m tried to use another class please help me, how can i solve java warning?

  12. #12
    Junior Member
    Join Date
    Sep 2012
    Location
    Bangladesh
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Encryption password by java MD5 and UTF-8

    Hello, I'm really tired to solve two warning. Below warnings show when i run above code. please give me some example, how can i solve this warning?

    MyPasswordEncryption.java:6: warning: sun.misc.BASE64Encoder is Sun proprietary API and may be removed in future release
    import sun.misc.BASE64Encoder;

    MyPasswordEncrypt.java:17: warning: sun.misc.BASE64Encoder is Sun proprietary API and may be removed in a future release
    hashValue = <new BASE64Encoder<>>.encode<rawByte>;
    2 warnings

    Thanks

  13. #13
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Encryption password by java MD5 and UTF-8

    how can i solve java warning?
    Find another class to do the Base64 encoding.
    If you don't understand my answer, don't ignore it, ask a question.

  14. #14
    Junior Member
    Join Date
    Sep 2012
    Location
    Bangladesh
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Encryption password by java MD5 and UTF-8

    Thanks for your reply, Actually i'm a new student on java class. Please explain me about Base64.
    how? Which one?

  15. #15
    Junior Member
    Join Date
    Sep 2012
    Location
    Bangladesh
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Encryption password by java MD5 and UTF-8

    Please help me with correct code. I did use another class but same problem have been still. I want to get some code without warning and errors.

    Thanks

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Encryption password by java MD5 and UTF-8

    Try using a search for base64 to find out about it.

    Perhaps you can find a free class that will do Base64 coding.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. How to do MD5 encryption in JSP for password login and registration?
    By sadaharu in forum JavaServer Pages: JSP & JSTL
    Replies: 4
    Last Post: June 21st, 2012, 11:58 AM
  2. Java encryption and decryption
    By frozen java in forum Java Theory & Questions
    Replies: 2
    Last Post: December 4th, 2011, 04:01 PM
  3. Java Encryption
    By xxcorrosionxx in forum What's Wrong With My Code?
    Replies: 6
    Last Post: February 9th, 2011, 04:12 AM
  4. Java password encryption
    By jmorr212 in forum JDBC & Databases
    Replies: 2
    Last Post: January 29th, 2011, 02:33 AM
  5. Basic Java Encryption
    By BronxBomber in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 9th, 2010, 10:50 PM

Tags for this Thread