KickJava   Java API By Example, From Geeks To Geeks.

Java > Java SE, EE, ME > java > security > MessageDigest

java.security
Class MessageDigest

java.lang.Object
  extended by java.security.MessageDigestSpi
      extended by java.security.MessageDigest
See Also:
Top Examples, Source Code, digest, reset, update, DigestInputStream, DigestOutputStream

public Object clone()
             throws CloneNotSupportedException
See Also:
Cloneable, MessageDigestSpi
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[358]Base64 encoding
By Anonymous on 2004/09/06 13:53:39  Rate
MessageDigest md = MessageDigest.getInstance ( "SHA" ) ; 
 byte [  ]  digest = md.digest ( "Original String to be encrypted".getBytes ( "iso-8859-1" )  ) ; 
 ByteArrayOutputStream bas = new ByteArrayOutputStream ( digest.length + digest.length / 4 + 1 ) ; 
 OutputStream encodedStream = MimeUtility.encode ( bas, "base64" ) ; 
 encodedStream.write ( digest ) ; 
 String newEncryptedString =  ( String )  bas.toString (  ) ; 
  
  
 //Clone 
 


public byte[] digest()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public byte[] digest(byte[] input)
See Also:
digest(), update(input)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1258]SHA encryption
By Muhammad Bilal Amin { dot } bilalamin { at } ieee { dot } org on 2005/05/30 02:03:35  Rate
String hash  ( String password )  
    {  
   StringBuffer strBuffer = new StringBuffer (  ) ; 
  
  
   try {  
       MessageDigest md = MessageDigest.getInstance ( "SHA1" ) ; 
       byte [  ]  passwordBytes = new byte [ 1024 ] ; 
       passwordBytes = password.getBytes (  ) ; 
       md.update ( passwordBytes ) ; 
       byte [  ]  hashedPwd = md.digest (  ) ; 
  
  
     for  ( int i=0;i < hashedPwd.length;i++ )  {  
       strBuffer.append ( toHexString ( hashedPwd [ i ] ,2 )  ) ; 
        }  
      } catch  ( Exception e )  {  
       System.out.println ( e ) ; 
      }  
  
  
     return strBuffer.toString (  ) ; 
    } 


public int digest(byte[] buf,
                  int offset,
                  int len)
           throws DigestException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public final String getAlgorithm()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public final int getDigestLength()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static MessageDigest getInstance(String algorithm)
                                 throws NoSuchAlgorithmException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static MessageDigest getInstance(String algorithm,
                                        String provider)
                                 throws NoSuchAlgorithmException,
                                        NoSuchProviderException
See Also:
Provider, IllegalArgumentException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static MessageDigest getInstance(String algorithm,
                                        Provider provider)
                                 throws NoSuchAlgorithmException
See Also:
IllegalArgumentException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public final Provider getProvider()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static boolean isEqual(byte[] digesta,
                              byte[] digestb)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


protected MessageDigest(String algorithm)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void reset()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public String toString()
See Also:
Object
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void update(byte input)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void update(byte[] input)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1423]_
By Welll I have a problem here on 2005/05/12 11:33:19  Rate
when I pass a attribute with single quotes, this fails

[1556]Calc MD5
By Anonymous on 2005/10/07 05:15:20  Rate
//Hash the additional data throghupdate (  )  methods 
  
  
 public static char [  ]  calcMD5 ( String filename, byte [  ]  extra )  
 throws Exception 
  {  
   FileInputStream fis = new FileInputStream ( filename ) ; 
   MessageDigest md = MessageDigest.getInstance ( "MD5" ) ; 
  
  
   try  {  
     DigestInputStream dis = new DigestInputStream ( fis, md ) ; 
     byte [  ]  buffer = new byte [ 8192 ] ; 
     while ( dis.read ( buffer )  != -1 )  
     ; 
    }  finally  {  
     fis.close (  ) ; 
    }  
  
  
   if ( extra != null && extra.length  >  0 )  
     md.update ( extra ) ; 
  
  
   byte [  ]  bDigest = md.digest (  ) ; 
   char [  ]  cDigest = new char [ 16 ] ; 
   for ( int i = 0; i  <  16; i++ )  
     cDigest [ i ]  =  ( char )  ( bDigest [ i ]  & 0xff ) ; 
  
  
   return cDigest; 
  }  


public void update(byte[] input,
                   int offset,
                   int len)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public final void update(ByteBuffer input)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  

Popular Tags