CAPICOM HashedData, java and binary files
From: Daniel Soriano (dsoriano_at_isoco.com)
Date: 03/29/05
- Next message: Ajith Kumar: "SSL Session caching"
- Previous message: Marco van Nieuwenhoven: "__file__ and __line__"
- Next in thread: Marco van Nieuwenhoven: "RE: CAPICOM HashedData, java and binary files"
- Reply: Marco van Nieuwenhoven: "RE: CAPICOM HashedData, java and binary files"
- Reply: Michel Gallant: "Re: CAPICOM HashedData, java and binary files"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
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?
- Next message: Ajith Kumar: "SSL Session caching"
- Previous message: Marco van Nieuwenhoven: "__file__ and __line__"
- Next in thread: Marco van Nieuwenhoven: "RE: CAPICOM HashedData, java and binary files"
- Reply: Marco van Nieuwenhoven: "RE: CAPICOM HashedData, java and binary files"
- Reply: Michel Gallant: "Re: CAPICOM HashedData, java and binary files"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|
|