download MD5.java
Language: Java
LOC: 29
Project Info
iwakiChat
Server: java.net
Type: cvs
...iwakichat\iwakichat\crypto\
   .nbattrs
   CertDisplayDialog.form
   CertDisplayDialog.java
   ClearSession.java
   DHSession.java
   MD5.java
   PasswordDialog.form
   PasswordDialog.java
   PasswordSession.java
   PKISession.java

/*
 * MD5.java
 *
 * Created on May 3, 2004, 2:23 PM
 */

package iwakichat.crypto;
import java.io.*;
import java.security.*;
import sun.misc.*;

/**
 *
 * @author  croberts
 * MD5.java will create a MD5 hash of the message
 * to be sent to the recipient.  The recipient will generate
 * it's own MD5 hash and compare the two.  If they are alike,
 *then everything is ok, otherwise, something has happend.
 *
 *The client should then respond back informing the sender that
 *the message was not intact and should be re-sent.
 *
 *This really wouldn't be too useful in plaintext mode because
 *a mitm attack possibly could send a forged MD5 hash to the 
 *recipient.  So why do you want to chat unprotected anyways?
 *
 *There is one way to verify the integrity of the message
 *while chatting in plain text.  Have the recipient send the MD5 
 *hash it created back to the sender.  Although this is not foolproof,
 *it's better than nothing.  Look for this to be done in the future.
 *Not soon though because this method would tend to create quite a bit
 *more traffic and slow things down a bit.
 *
 *
 */
public class MD5 {
    String message;
    public String MD5(java.lang.String message) {
    this.message=message;
    try
        {
        MessageDigest md = MessageDigest.getInstance("MD5");
        String md5string="";
        StringBuffer sb = new StringBuffer();
        byte buf[] = message.getBytes();
        byte[] md5 = md.digest(buf);
        System.out.println(message);
        for( int i = 0 ; i < md5.length ; i++ ) {
        String tmpStr = "0"+Integer.toHexString( (0xff & md5[i]));
        sb.append(tmpStr.substring(tmpStr.length()-2));
        }       
    System.out.println(md5string = sb.toString());
    return (md5string);
}
catch (Exception e)
{
System.out.println(e);
}
    
    }
    
   
}

About Koders | Resources | Downloads | Support | Black Duck | Submit Project | Terms of Service | DMCA | Privacy Policy | Site Map| Contact Us