CAPICOM HashedData, java and binary files

From: Daniel Soriano (dsoriano_at_isoco.com)
Date: 03/29/05


Date: 29 Mar 2005 01:58:33 -0800

I'm generating a hash with CAPICOM(v2.0.0.3).HashedData (algorithm
SHA1) in this form in order to not to create a big buffer in memory:

    Dim oHashedData As New CAPICOM.HashedData
    Dim oUtilities As New CAPICOM.Utilities
    Dim max_buffer As Integer
    Dim contador As Integer
    Dim i As Long
    Dim l As Long
    Dim t As Long
    Dim j As Long
    
    Dim lbFile() As Byte
    
    max_buffer = 512
    contador = 0
    oHashedData.Algorithm = CAPICOM_HASH_ALGORITHM_SHA1
    Text2.Text = ""
    Open Text1.Text For Binary As #1
    l = LOF(1)
    i = 0
    While i < l
        If (l - i) > 512 Then
            t = max_buffer
        Else
            t = l - i
        End If
        ReDim lbFile(t)
        Get #1, , lbFile
        
        i = i + t
        oHashedData.Hash oUtilities.ByteArrayToBinaryString(lbFile)
        Text2.Text = Text2.Text & contador & " " & _
 oUtilities.Base64Encode(oUtilities.HexToBinary(oHashedData.Value)) &
_
                    vbNewLine
        contador = contador + 1
    Wend
    Close #1

This doesn't generate the same hash with a java this program:

FileInputStream fin = new
FileInputStream("F:\\jakarta-tomcat-4.1.30\\bin\\CERTIFICADO_ALTA_ASEMAS.zip");

        MessageDigest digest = MessageDigest.getInstance("SHA1"); //,
"BC");
        int max_buffer = 512;
        byte[] buffer = new byte[512];
        String byteEncoding = new String("UnicodeLittleUnmarked");
        
        int bytesReaded = 0;
        int contador = 0;
        while ((bytesReaded=fin.read(buffer)) !=-1){
            ByteArrayOutputStream output = new ByteArrayOutputStream
();
            for (int i=0;i<bytesReaded;i++)
                output.write (buffer[i]);
            
            
            digest.update(output.toByteArray());
            byte[] digBytes =
org.bouncycastle.util.encoders.Base64.encode(digest.digest());
            System.out.println(contador+" "+(new String(digBytes)));
            contador ++;
        }

I have tested that hashing runs perfectly when using text files and
java program update digest with "UnicodeLittleUnmarked" bytes, but
with binary files seems always not running. Why is the right way to do
this?



Relevant Pages

  • Re: Hash a range, output a Long Integer?
    ... Re the GetMD5Hash function in the root message. ... The problem with GetMD5Hash is I get the same hash if the cell value is ... I get a hash that that changes on the content of the cells. ... Dim hHash As Long ...
    (microsoft.public.excel.programming)
  • Re: Hash a range, output a Long Integer?
    ... I noticed that the hash value does not change if I change a cell value from ... > While Stephen's original function returns a 30 character string, ... > Dim hProv As Long ...
    (microsoft.public.excel.programming)
  • Re: Hash in Array speichern ?
    ... Um dann den Hash im folgenden Arrayindex abzulegen. ... > Dim myHash As New Hashtable ... > Dim myHash2 As New Hashtable ...
    (microsoft.public.de.german.entwickler.dotnet.vb)
  • Re: Question on a Chip Pearson macro
    ... ....best, Hash ... Martin Fishlock wrote: ... >> Deleting Duplicate Rows is something I want to do. ... >> Dim Col As Integer ...
    (microsoft.public.excel.programming)
  • Compare datasets with hash values or possibly another way?
    ... hash values of the datasets and compare those. ... ' Create a new instance of memory stream ... Dim formatter As New BinaryFormatter ...
    (microsoft.public.vstudio.general)