Hi!
I'm using the Phil Fresle's CSHA256 class on the VB6, but it doesn't work on the 2010 for syntax errors. Is there a way or another class to make it work ? If yes, where can i download that?
Sorry for mistakes, but i'm not english !
Printable View
Hi!
I'm using the Phil Fresle's CSHA256 class on the VB6, but it doesn't work on the 2010 for syntax errors. Is there a way or another class to make it work ? If yes, where can i download that?
Sorry for mistakes, but i'm not english !
What are the syntax errors? We might be able to help you fix them.
EDIT: Noticed you said vb6. Of course it's going to have syntax errors. It pays if I read the entire OP actually before posting. You could try searching for a .NET version of SHA256 since there is a managed class for that now.
It underline "Private Function R(ByVal x As Long, ByVal n As Long) As Long" and says: "Istruzione non valida in uno spazio dei nomi", in english "instruction not valid in a namespace" (?)Code:'*******************************************************************************
' R (FUNCTION)
'
' DESCRIPTION:
' SHA-256 function (just a right shift)
'*******************************************************************************
Private Function R(ByVal x As Long, ByVal n As Long) As Long
R = RShift(x, CInt(n And m_lOnBits(4)))
End Function
This for all function in the class
It says also: "The instruction option explicit can be contained one time per file" (?)
Here's some light reading about the .NET SHA256 class. No need to try to get someone else's file working for you when it's built right in to the framework.
For the record, you're getting that error because you can't just drop a function in a namespace; it has to live in a class. You could probably fix it, but I don't think it's worth even the 2 lines you'd have to add. For example, this is wrong for some file "Utilities.vb":
This is correct:Code:Public Sub DoSomething()
End Sub
Code:Public Class Utilities
Public Sub DoSomething()
End Sub
End Class
That was a bit short; here's an example of using it.
Note the use of SHA256CryptoServiceProvider instead of SHA256Managed. The "Managed" classes aren't compliant with some security standard called FIPS and have been a pain in my rear for the past two years.Code:Module Module1
Sub Main()
Dim filePath As String = "C:\temp\test.txt"
Dim shaAlgorithm = System.Security.Cryptography.SHA256CryptoServiceProvider.Create()
Dim hash() As Byte
Using inputStream As New System.IO.FileStream(filePath, System.IO.FileMode.Open)
hash = shaAlgorithm.ComputeHash(inputStream)
End Using
Console.WriteLine("Here's the SHA256 hash:")
For i As Integer = 0 To hash.Length - 1
Console.Write("{0:X2} ", hash(i))
If i = 79 Then
Console.WriteLine()
End If
Next
End Sub
End Module
I don't know because i need only to use this class and,unfortunatly,i don't know how it works. Here you can see the class
Did you read #5? That was a good supplement to the examples in the documentation I linked. You either hand ComputeHash() an array of Byte values or give it a stream; I used a stream. It returns an array of Byte with the hash values. It doesn't get much simpler.
You don't know how to use that other class either, so why not stick with the one that has several .NET examples?