KickJava   Java API By Example, From Geeks To Geeks.

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

java.security
Class DigestInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by java.io.FilterInputStream
          extended by java.security.DigestInputStream
All Implemented Interfaces:
Closeable
See Also:
Top Examples, Source Code, on, read, MessageDigest, DigestOutputStream

protected MessageDigest digest
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1555]Hashing data from streams
By Anonymous on 2005/10/07 05:11:14  Rate
//hashing data from streams 
 public static char [  ]  calcMD5 ( String filename )  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 (  ) ; 
  }  
  
  
 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 DigestInputStream(InputStream stream,
                         MessageDigest digest)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public MessageDigest getMessageDigest()
See Also:
setMessageDigest(java.security.MessageDigest)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


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


public int read()
         throws IOException
See Also:
MessageDigest.update(byte), FilterInputStream, on
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public int read(byte[] b,
                int off,
                int len)
         throws IOException
See Also:
MessageDigest.update(byte[], int, int), FilterInputStream, on
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void setMessageDigest(MessageDigest digest)
See Also:
getMessageDigest()
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  

Popular Tags