java.lang.Object
java.io.InputStream
java.io.FilterInputStream
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