Comments
yourfanat wrote: I am using another tool for Oracle developers - dbForge Studio for Oracle. This IDE has lots of usefull features, among them: oracle designer, code competion and formatter, query builder, debugger, profiler, erxport/import, reports and many others. The latest version supports Oracle 12C. More information here.
Cloud Expo on Google News
SYS-CON.TV
Cloud Expo & Virtualization 2009 East
PLATINUM SPONSORS:
IBM
Smarter Business Solutions Through Dynamic Infrastructure
IBM
Smarter Insights: How the CIO Becomes a Hero Again
Microsoft
Windows Azure
GOLD SPONSORS:
Appsense
Why VDI?
CA
Maximizing the Business Value of Virtualization in Enterprise and Cloud Computing Environments
ExactTarget
Messaging in the Cloud - Email, SMS and Voice
Freedom OSS
Stairway to the Cloud
Sun
Sun's Incubation Platform: Helping Startups Serve the Enterprise
POWER PANELS:
Cloud Computing & Enterprise IT: Cost & Operational Benefits
How and Why is a Flexible IT Infrastructure the Key To the Future?
Click For 2008 West
Event Webcasts
Frank's Java Code Stack #4 Using Message Digest Stream
Frank's Java Code Stack #4 Using Message Digest Stream

(November 12, 2002) - In Java Code Stack #1 and #3, we observed some code snippets on both Symmetric and Asymmetric Cryptography. But most of our applications, such as password authentication and logon verification, need a simpler way of creating a Digest of a given string or a message. Message Digest is a hash algorithm that takes as input a message of arbitrary length and produces as output a 128-bit fingerprint or message digest of the input. This Digest algorithm is meant for digital signature applications, where a large file/Data must be compressed in a secure manner before being encrypted with a Secret key under a public key crypto model. But instead of passing a byte array to the Digest system, we can pipe a stream to the Digest object for reading and writing Digest directly into the stream. This week, we'll build one such class, which performs a Digest for a string and writes it to a stream.

Code:

  1.        import java.io.*;
  2.        import java.security.*;

  3.        public class msgStream{
  4.        public static void main(String ar[]){

  5.        try{
  6.        /* Let us write the Digest to a
  7.        File Stream */
  8.        FileOutputStream fos=
           new FileOutputStream("MyDigest");
  9.        /* We are using SHA1 Algorithm */
  10.        MessageDigest md=
           MessageDigest.getInstance("SHA1");

  11.        /* A transparent stream that
           updates the associated message
           digest using the bits going
           through the stream. */
  12.        DigestOutputStream dos=
           new DigestOutputStream(fos, md);
  13.        ObjectOutputStream oos=
           new ObjectOutputStream(dos);

  14.        /* String to be processed */
  15.        String text="This class
           works with Digest Streams";
  16.        oos.writeObject(text);

  17.        /* Before writing the digest
           to the Stream, turn the
           Digest OFF. When it is off,
           a call to one of the write
           methods does not result
           in an update on the
           message digest. However you        can ignore this.*/
  18.        dos.on(false);
  19.        oos.writeObject(md.digest());
  20.        }catch(Exception e){}

  21.        try{
  22.        /* Read the Digest from
           the File Stream */
  23.        FileInputStream fis=
  24.        new FileInputStream("MyDigest");

  25.        MessageDigest md=
           MessageDigest.getInstance("SHA1");

  26.        DigestInputStream dis=
           new DigestInputStream(fis,md);
  27.        ObjectInputStream ois=
           new ObjectInputStream(dis);
  28.        String text=(String)ois.readObject();

  29.        /* We got the Original Text..
           Not the Digest! */
  30.        System.out.println(""+text);

  31.        dis.on(false);
  32.        byte rdigest[]=
           (byte[]) ois.readObject();

  33.        /* Comparing the Digest of the
           String with the Original Digest */
  34.        if(MessageDigest.isEqual
           (md.digest(), rdigest))
  35.        System.out.println("Valid Messg.");
  36.        else
  37.        System.out.println("Invalid Messg.");
  38.        }catch(Exception e){}

  39.        }
  40.        }

As you can see, the DigestOutputStream allows us to write Data to any Output Stream and calculate the Message Digest of that Data transparently as the Data passes through the Stream. Note that unlike usual Message Digest calculation, which involves only the Data, we are calculating the Digest over the serialized String Object, which can have additional information like Class definition along with the Data.

Assignment:
Try to build a Secure Message Digest (MAC) by using any standard Encryption Engine.

In order to post a comment you need to be registered and logged in.

Register | Sign-in

Reader Feedback: Page 1 of 1

Latest Cloud Developer Stories
We are seeing a major migration of enterprises applications to the cloud. As cloud and business use of real time applications accelerate, legacy networks are no longer able to architecturally support cloud adoption and deliver the performance and security required by highly distr...
Business professionals no longer wonder if they'll migrate to the cloud; it's now a matter of when. The cloud environment has proved to be a major force in transitioning to an agile business model that enables quick decisions and fast implementation that solidify customer relatio...
DXWorldEXPO LLC announced today that "IoT Now" was named media sponsor of CloudEXPO | DXWorldEXPO 2018 New York, which will take place on November 11-13, 2018 in New York City, NY. IoT Now explores the evolving opportunities and challenges facing CSPs, and it passes on some lesso...
SYS-CON Events announced today that Silicon India has been named “Media Sponsor” of SYS-CON's 21st International Cloud Expo, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Published in Silicon Valley, Silicon India magazin...
In his general session at 19th Cloud Expo, Manish Dixit, VP of Product and Engineering at Dice, discussed how Dice leverages data insights and tools to help both tech professionals and recruiters better understand how skills relate to each other and which skills are in high deman...
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021



SYS-CON Featured Whitepapers
ADS BY GOOGLE