carl
New Member
Posts: 4
|
Post by carl on Aug 28, 2008 5:25:32 GMT -5
Hi, first i want to thank to you for makin this dll for vb, it's very grateful and helpfull to have this dll.
okay, i want to tell my problem, i have a program to make hash from text, the program was built in visual studio 2005, c#! but i want to use that hash in visual basic 6.0.
After i found this dll, i used it, and ia get a different result between 2 application.
i want to ask, what is the different between mscorlib.dll and vbcorlib.dll??? do you know how can i find the solve for my problem?
thanks a lot before
just to know: in c#2005:
byte[] dataToHash = ConvertStringToByteArray(password); byte[] hashValue = ((HashAlgorithm)CryptoConfig.CreateFromName("SHA1")).ComputeHash(dataToHash);
StringBuilder sb = new StringBuilder(BitConverter.ToString(hashValue)); sb.Replace("-", "");
;D
|
|
|
Post by Kelly Ethridge on Aug 28, 2008 12:11:16 GMT -5
Hello carl!
There shouldn't be any difference with generating a hash value from the two libraries. Looking at the code, I have to wonder what ConvertStringToByteArray actually does. Can you give me a complete sample that shows the wrong hash value being calculated?
Thanks, Kelly
|
|
carl
New Member
Posts: 4
|
Post by carl on Aug 28, 2008 21:21:31 GMT -5
HI Kelly
ConvertStringToByteArray is to make an array of byte from a string using its ASCII for example carl = 99-0-97-0-114-0-108-0
i give you the difference for text = carl in VS2005(mscorlib.dll) = 7452FAB02272C8DC36599CB213DC1E54176F0068 in VB6(vbcorlib.dll) = 0CC00FEADC04F06C9B6152CA7BCCDDEE55CE34B1
it's very helpful if you can help me to solve that's problem
thx a lot
NB: code in VB:
Option Explicit
Dim a As HashAlgorithm
Private Sub Text1_Change() Call ComputeHashes(Text1.Text) End Sub
Private Sub ComputeHashes(ByVal Text As String) Dim i As Integer Dim kata1() As Byte Dim pjg As Integer pjg = Len(Text) * 2 ReDim kata1(pjg) As Byte For i = 0 To Len(Text) - 1 kata1(2 * i) = Asc(Mid(Text, i + 1, 1)) kata1((2 * i) + 1) = 0 Next i
Call DisplayHash(mSha1.ComputeHash(kata1), Text2, Text5) Set a = CryptoConfig.CreateFromName("SHA1") Call DisplayHash(a.ComputeHash(kata1), Text3, Text4) End Sub
Private Sub DisplayHash(ByRef Hash() As Byte, ByVal Box As TextBox, ByVal Box1 As TextBox) Dim sb As New StringBuilder Dim sb1 As New StringBuilder sb.Length = 0 sb1.Length = 0 Dim i As Long For i = 0 To UBound(Hash) 'If (i > 0) And ((i Mod 16) = 0) Then Call sb.AppendLine Call sb.AppendFormat("{0:X2}", Hash(i)) Call sb1.Append(Hash(i)) 'abc = abc & Hash(i) Next i Box.Text = sb.ToString Box1.Text = sb1.ToString 'Box.Text = abc End Sub
|
|
|
Post by Kelly Ethridge on Aug 28, 2008 21:42:41 GMT -5
Hello carl,
I see the problem. Your redim of kata1 is one byte too long.
Change
ReDim kata1(pjg) As Byte
To
ReDim kata1(pjg - 1) As Byte
You were hashing an additional 0 character.
As a side note, you can use the Unicode encoding to get the same string-to-bytes result as your loop.
Dim kata1() As Byte kata1 = Encoding.Unicode.GetBytes(Text)
Kelly
|
|
carl
New Member
Posts: 4
|
Post by carl on Aug 29, 2008 0:11:56 GMT -5
oh yeah
thx very much, at least i know what's my problem. thx, it's already worked now, i'm so happy
thx again for your best dll
now i will use this dll to include in my project hehehe if something trouble, i will ask you again
thx a lot
|
|
carl
New Member
Posts: 4
|
Post by carl on Nov 20, 2008 22:29:41 GMT -5
Hello Kelly,
i want to ask you again about this vbcorlib.dll
in . net, i found PasswordDeriveBytes what the simillar class in vb corlib, because i want to make Rijndael Encryption, but i stack on this problem, thx a lot
|
|
|
Post by Kelly Ethridge on Nov 21, 2008 13:04:54 GMT -5
Hi Carl,
I didn't include the PasswordDeriveBytes class because it was being phased out from what I've read. The class to be used instead is Rfc2898DeriveBytes. It doesn't generate the same keys as PasswordDeriveBytes so it isn't a direct replacement. I may implement the PasswordDeriveBytes in the future, but, so far you're the only one who has mentioned it.
Kelly
|
|