Results 1 to 2 of 2
  1. #1
    Danny is offline Member
    Join Date
    Nov 2013
    Posts
    1
    Rep Power
    0

    Default Cryptographic hash of a message

    Hi, this is my first post on this site. I have a program that Decrypts a file with a String stored in it and displays that message to the console. What I want to do next is display a Cryptographic hash of that message. I am wondering how I would do this? Any help would be greatly appreciated. Here is the code...

    Java Code:
    import java.io.*;
    import java.security.*;
    import javax.crypto.*;
    
    public class RSADecrypt
    {
      public static void main(String args[])
      {
        /**
         * Decrypts message provided in file and writes to standard output
         */
    
        try
        {
          // File containing RSA private key
          FileInputStream keyFIS = new FileInputStream("RSAPrivateKeyFile");
          ObjectInputStream keyOIS = new ObjectInputStream(keyFIS);
    
          // Create RSA cipher instance
          Cipher rsaCipher = Cipher.getInstance("RSA");
    
          // Initialize the cipher for encryption
          rsaCipher.init(Cipher.DECRYPT_MODE, (PrivateKey) keyOIS.readObject());
    
          keyOIS.close();
          keyFIS.close();
    
          // Read ciphertext from file and decrypt it
          FileInputStream fis = new FileInputStream("scrambled");
          BufferedInputStream bis = new BufferedInputStream(fis);
          CipherInputStream cis = new CipherInputStream(bis, rsaCipher);
    
          StringBuffer plaintext = new StringBuffer();
          int c;
          while ((c = cis.read()) != -1)
            plaintext.append((char) c);
          cis.close();
          bis.close();
          fis.close();
    
          System.out.println("Plaintext: " + plaintext.toString());
    
        }
        catch (Exception e)
        {
          System.out.println(e);
        }
      }
    }

  2. #2
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,418
    Rep Power
    5

    Default Re: Cryptographic hash of a message

    Check out the Message Digest classes in the JDK API.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

Similar Threads

  1. Hash
    By CodeX Pro in forum New To Java
    Replies: 7
    Last Post: 06-07-2013, 05:32 PM
  2. Replies: 9
    Last Post: 11-12-2012, 11:38 AM
  3. Replies: 6
    Last Post: 06-04-2010, 08:43 PM
  4. Hash
    By sandy1028 in forum New To Java
    Replies: 4
    Last Post: 04-17-2009, 10:36 AM
  5. Hash Map
    By rekha in forum New To Java
    Replies: 1
    Last Post: 03-21-2009, 01:00 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •