Presentation is loading. Please wait.

Presentation is loading. Please wait.

LAB#6 MAC & MASSAGE DIGEST CPIT 425. Message Authentication 2  Message authentication is a mechanism used to verify the integrity of a message.  Message.

Similar presentations


Presentation on theme: "LAB#6 MAC & MASSAGE DIGEST CPIT 425. Message Authentication 2  Message authentication is a mechanism used to verify the integrity of a message.  Message."— Presentation transcript:

1 LAB#6 MAC & MASSAGE DIGEST CPIT 425

2 Message Authentication 2  Message authentication is a mechanism used to verify the integrity of a message.  Message authentication assures that:  The data received are exactly as sent by (contain no modification, insertion …).  The purported identity of the sender is valid.  The two most common cryptographic techniques for message authentication are:  Message Authentication Code (MAC)  Secure hash function

3 Message Authentication Code MAC 3  MAC is an algorithm that requires the use of a secret key.  MAC takes a variable-length message and a secret key as input and produces an authentication code.  Typically, message authentication codes are used between two parties, say Alice and Bob, that share a secret key K in order to validate information transmitted between these parties.  When Alice has a message to send to Bob, she calculates the MAC as a function of the message and the key:  MAC = C(K, M) where M=input message, C=MAC function, K=shared secret key.

4 Message Authentication Code MAC 4  Alice sends to Bob a document as well as a MAC. Bob can authenticate who sent the document by performing the same MAC on the document and comparing his MAC to the one that Alice sent. If they match, he knows that Alice sent the document. diamond icon represents a comparison process

5 Message Authentication Code MAC in Java 5  Java Package: javax.crypto  Java Class : Mac  Methods: getInstance(), init(), update(), doFinal().  Algorithms: HMAC (Hashed MAC) functions supported by JCE:  HmacMD5 and HmacSHA1

6 Message Digests 6  As with MAC, a hash function accepts a variable- size message M as input and produces a fixed-size output referred to as a hash code(message digest).  Unlike MAC, a hash code does not use a key but is a function only of the input message.  Message digest: Given a message M of arbitrary length, a public function (i.e. hash function) H will produce a fixed-sized output called message digest or hash value h by a function of the form h=H(M).  message (M)  hashing algorithm(H)  digest (h)

7 Message Digests in Java 7  Java package: java.security  Java class: MessageDigest  Methods: getInstance(), reset(), update(), digest().  Algorithms: MD5, SHA, SHA-1

8 Message Digests in Java 8  MessageDigest getInstance(String algorithm) Generates a MessageDigest object that implements the specified digest algorithm.  byte[] digest() Completes the hash computation by performing final operations.  byte[] digest(byte[] input) Performs a final update on the digest using the specified array of bytes, then completes the digest computation.  void update(byte[] input) Updates the digest using the specified array of bytes.  void reset() Resets the digest for further use.

9 Message Digests in Java 9  MessageDigest Class: A MessageDigest object starts out initialized. 1. The data is processed through it using the update methods. 2. Once all the data to be updated has been updated, one of the digest methods should be called once to complete the hash computation. 3. After digest has been called, the MessageDigest object is reset to its initialized state.  Ex: MessageDigest sha = MessageDigest.getInstance("SHA-1"); sha.update(data1); // data1 is a byte array that holds the original massage byte[] msgDigest = sha.digest(); sha.reset(); sha.update(data2);....

10 Message Digests in Java 10 Alternative classes for computing a message digest on a file: DigestInputStream and DigestOutputStream  Java pakage: java.security  DigestInputStream class:  To complete the message digest computation, call one of read methods. Then call one of the digest methods on the associated message digest.  int read() : Reads a byte, and updates the message digest and then return an integer value of the byte that it read.  Ex: FileInputStream in = new FileInputStream("MD.txt"); MessageDigest md = MessageDigest.getInstance("MD5"); DigestInputStream digestIn = new DigestInputStream(in, md);

11 Message Digests in Java 11  Java pakage: java.security  DigestOutputStream  To complete the message digest computation, call one of the digest methods on the associated message digest after that call one of the write methods.  void write(byte[] b) : Updates the message digest using the specified array, and in any case writes the array to the output stream.  Ex: MessageDigest md = MessageDigest.getInstance("MD5"); FileOutputStream out = new FileOutputStream("MDout.txt"); DigestOutputStream dout = new DigestOutputStream(out, md);

12 LAB WORK 12  Write a program that implements Massage Digest using MD5 and SHA-1 algorithms. For each algorithm, digests different string and notice the size of the output. Note: Size of the output digest (SHA-1: 20 bytes MD5: 16 bytes)

13 HOMEWORK#3 13 write a client/server program that uses the message digest. The Client.java file creates an MD5 message digest, reads a massage from a file (MD.txt) and displays the massage digest in another file (MDout.txt) then displays the contents and the size of the digest array on the standard output. The Server.java file creates an MD5 message digest and reads the massage from a file (MD.txt). Then it reads the message digest that is created by the client side from MDout.txt to compare it with the message digest created by the server side. If they are equal, the server will display “The two message digest are matched ”, else the server will display “The two message digest are not matched”. (NOTE: use DigestInputStream and DigestOutputStream classes to solve the homework)

14 HOMEWORK#3 14  Submit the following(hard copy + soft copy): 3 programs(MAC, lab work, HW#2)+ output of each one+ txt files (MD.txt + MDout.txt)  Due date: next lab   continue in the next slide

15 HOMEWORK#3 15  Read this text from the input file (MD.txt): A message digest or hash function is used to turn input of arbitrary length into an output of fixed length, which is called the digest or hash of the input. This output can then be used in place of the original input. This has many advantages. The output always has the same length, so this can be taken into account when processing or storing the message digest. Also, the output is much shorter than the input, so that processing and storing can be done much quicker. The most common cryptographic hash function is MD5. MD5 was designed by well-known cryptographer Ronald Rivest in 1991. In 2004, some serious flaws were found in MD5. The complete implications of these flaws has yet to be determined. Another popular hash function is SHA-1.


Download ppt "LAB#6 MAC & MASSAGE DIGEST CPIT 425. Message Authentication 2  Message authentication is a mechanism used to verify the integrity of a message.  Message."

Similar presentations


Ads by Google