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 5 of 5

Thread: Setting up a SHA-256 hash for multiple passwords

  1. #1
    Junior Member
    Join Date
    Nov 2013
    Posts
    19
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Setting up a SHA-256 hash for multiple passwords

    Here is an example of SHA-256 hash coding one can find anywhere on the web:
          import java.security.MessageDigest;
     
          public class SHAHashingExample 
          {
              public static void main(String[] args)throws Exception
              {
        	      String password = "0000000000000000";
     
                  MessageDigest md = MessageDigest.getInstance("SHA-256");
                  md.update(password.getBytes());
     
                  byte byteData[] = md.digest();
     
                  //convert the byte to hex format method 1
                  StringBuffer sb = new StringBuffer();
                  for (int i = 0; i < byteData.length; i++) {
                   sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));
                  }
     
                  System.out.println("Hex format : " + sb.toString());
     
                  //convert the byte to hex format method 2
                  StringBuffer hexString = new StringBuffer();
        	      for (int i=0;i<byteData.length;i++) {
        		      String hex=Integer.toHexString(0xff & byteData[i]);
       	     	      if(hex.length()==1) hexString.append('0');
       	     	      hexString.append(hex);
        	      }
        	      System.out.println("Hex format : " + hexString.toString());
              }
          }
    Is there a way to set it up so it can output for multiple "passwords"? Example, instead of only outputing fcdb4b423f4e5283afa249d762ef6aef150e91fccd810d43e5 e719d14512dec7 with the above coding, I want to have an output of every possible 16 digit hex value. I understand the output will be huge if I run the entire 0000000000000000 through ffffffffffffffff sequence (16^16 = 18 quintillion+ results). But I want my output to look like this:

    0000000000000000 fcdb4b423f4e5283afa249d762ef6aef150e91fccd810d43e5 e719d14512dec7
    0000000000000001 665e994827f6b03167e80c1513eb356e0d4f013f2e03a3b345 e1e5e3c24dfca6
    and so on until...
    ffffffffffffffff 6534b338bcb91cf173444c24ed8bc0f1b7065face0ea95cdd1 b936556c6860ed

    As new as I am to coding, I understand that this is a LARGE amount of data and I'll also need a way to export the output I create into a text editor (likely notepad). Any assistance would be greatly appreciated.


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Setting up a SHA-256 hash for multiple passwords

    Please read this FAQ to learn how to post code correctly along with other useful info for newcomers.

    Do you know how to use loops? You've essentially answered your own question, and I'm' not sure what you need help with.

  3. The Following User Says Thank You to GregBrannon For This Useful Post:

    Djinn (November 17th, 2013)

  4. #3
    Junior Member
    Join Date
    Nov 2013
    Posts
    19
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Re: Setting up a SHA-256 hash for multiple passwords

    I thought may Iteration through a Hash map may be the answer for looping I needed, but in looking through example code and reading the site below:
    http://www.javaprogrammingforums.com...iteration.html
    Iteration may not be what I need... Will continue documenting what I learn.

  5. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Setting up a SHA-256 hash for multiple passwords

    I don't want to discourage whatever it is about this project that has you excited to learn to program, but I advise you to NOT bounce around the Internet, chasing design ideas based on limited to no understanding, cobbling bits of code together that you don't understand into a broken mess that you have no idea how to fix, to finally discovering that you can't find anyone to help you fix it. Ultimately, this will result in you being discouraged, making all kinds of inaccurate conclusions about programming, programmers, and your abilities.

    So slow down, just a bit, and learn the basics from which to build a solid foundation on which projects like this can be built. Variables, variable types, operators, logic control/branching/looping tools are essentially common to all programming languages with varying syntax. Do the Java Language Basics tutorials. You can become an expert at them in a couple of weeks or less, depending on how much time and effort you can put into it.

    Then come back to this with new knowledge and ideas on how attack this problem. You have the time to invest, and it'll be a worthwhile investment.

  6. The Following User Says Thank You to GregBrannon For This Useful Post:

    Djinn (November 17th, 2013)

  7. #5
    Junior Member
    Join Date
    Nov 2013
    Posts
    19
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Default Re: Setting up a SHA-256 hash for multiple passwords

    Gotcha. Many thanks.

Similar Threads

  1. AES-256
    By 0w1 in forum Java Theory & Questions
    Replies: 0
    Last Post: July 19th, 2013, 11:16 PM
  2. Password Hash - Brute Force Test - SHA-1
    By djl1990 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: February 14th, 2012, 03:36 PM
  3. Need help with checking passwords
    By kb1213 in forum What's Wrong With My Code?
    Replies: 11
    Last Post: April 12th, 2011, 05:32 PM
  4. Need help with setting multiple font styles in jTextPane
    By jch02140 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: January 23rd, 2010, 06:16 AM

Tags for this Thread