Results 1 to 7 of 7

Thread: SHA256 Digest

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2011
    Posts
    4

    Arrow SHA256 Digest

    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 !

  2. #2

    Re: SHA256 Digest

    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.
    Last edited by formlesstree4; May 27th, 2011 at 02:46 PM.

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2011
    Posts
    4

    Re: SHA256 Digest

    Quote Originally Posted by formlesstree4 View Post
    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.
    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
    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" (?)
    This for all function in the class
    It says also: "The instruction option explicit can be contained one time per file" (?)

  4. #4
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: SHA256 Digest

    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":
    Code:
    Public Sub DoSomething()
    End Sub
    This is correct:
    Code:
    Public Class Utilities
        Public Sub DoSomething()
        End Sub
    End Class
    Last edited by Sitten Spynne; May 27th, 2011 at 03:08 PM.

  5. #5
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: SHA256 Digest

    That was a bit short; here's an example of using it.
    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
    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.

  6. #6

    Thread Starter
    New Member
    Join Date
    May 2011
    Posts
    4

    Re: SHA256 Digest

    Quote Originally Posted by Sitten Spynne View Post
    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

  7. #7
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,578

    Re: SHA256 Digest

    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?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width