Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Revision on Byte to Hexadecimal
Message
De
03/02/2014 11:19:58
 
 
À
03/02/2014 11:08:13
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01592982
Message ID:
01593007
Vues:
27
Looks like you forgot the using for New MD5CryptoServiceProvider()



>>That was easy - you are using SHA256Managed which returns a 32 byte array
>>
>>
>>//  loSHA256 = SHA256Managed.Create()
>>
>>using ( MD5 md5Hash = MD5.Create() )
>>
>
>This has resolved the issue. It provides, of course, a new MD5 value. This is the updated code:
>
>
>Imports System.IO
>Imports System.Security.Cryptography
>
>Public Class MD5
>
>    Public cMessage As String = ""
>    Public cFileName As String = ""
>    Public lLogError As Boolean = True
>    Public oMD5() As Byte = Nothing
>    Private cFileDoesNotExist As String = ""
>    Private nLanguage As Integer = 0
>    Private oApp As Framework.App = Nothing
>    Private oProcess As Framework.LXProcess = Nothing
>
>    ' This is when we access the class in a desktop mode
>    Sub New(ByVal toApplication As Framework.App)
>        oApp = toApplication
>        nLanguage = oApp.nLanguage
>        Init()
>    End Sub
>
>    ' This is when we access the class in a Web or Web Service mode
>    Public Sub New(ByVal toProcess As Framework.LXProcess)
>        oProcess = toProcess
>        oApp = oProcess.oApp
>        nLanguage = oProcess.nLanguage
>        Init()
>    End Sub
>
>    Private Function Init() As Boolean
>
>        ' Based on the language
>        Select Case nLanguage
>
>            ' English
>            Case 1
>                cFileDoesNotExist = "The file ##File## does not exist."
>
>                ' French
>            Case 2
>                cFileDoesNotExist = "Le fichier ##File## n'existe pas."
>
>                ' Spanish
>            Case 3
>                cFileDoesNotExist = "The file ##File## does not exist."
>
>                ' Portuguese
>            Case 4
>                cFileDoesNotExist = "The file ##File## does not exist."
>
>        End Select
>
>        Return True
>    End Function
>
>    ' Get the MD5
>    Public Function GetMD5() As Boolean
>        Dim lcMessage As String = ""
>        Dim lnCounter As Integer = 0
>        Dim lnDelay As Integer = 250
>        Dim lnRetry As Integer = 8
>        Dim loMD5CryptoServiceProvider As MD5CryptoServiceProvider = New MD5CryptoServiceProvider()
>
>        ' Reset the values
>        cMessage = ""
>        oMD5 = Nothing
>
>        ' We retry up to 8 times
>        For lnCounter = 1 To lnRetry
>
>            Try
>
>                ' If the file exists
>                If oApp.FileExist(cFileName) Then
>
>                    ' Open the destination
>                    Using loStream As Stream = New FileStream(cFileName, FileMode.Open)
>
>                        ' Compute the hash of the fileStream
>                        oMD5 = loMD5CryptoServiceProvider.ComputeHash(loStream)
>
>                    End Using
>
>                Else
>                    lcMessage = oApp.StrTran(cFileDoesNotExist, "##File##", cFileName)
>
>                    ' If we log the error
>                    If lLogError Then
>
>                        ' Get the proper definition as per the current scope
>                        If oProcess Is Nothing Then
>                            oApp.ErrorSetup(, lcMessage)
>                        Else
>                            oProcess.ErrorSetup(, lcMessage)
>                        End If
>
>                    Else
>                        cMessage = lcMessage
>                        Return False
>                    End If
>
>                End If
>
>                Exit For
>
>            Catch loError As Exception
>
>                ' If we have not reached the maximum tries of 8, we retry
>                If lnCounter < 8 Then
>
>                    ' Wait for a timeout before retrying
>                    System.Threading.Thread.Sleep(lnDelay)
>
>                    Continue For
>                End If
>
>                ' If we log the error
>                If lLogError Then
>
>                    ' Get the proper definition as per the current scope
>                    If oProcess Is Nothing Then
>                        oApp.ErrorSetup(loError)
>                    Else
>                        oProcess.ErrorSetup(loError)
>                    End If
>
>                Else
>                    cMessage = loError.Message
>                    Return False
>                End If
>
>            End Try
>
>        Next
>
>        ' Reset the values
>        cFileName = ""
>
>        Return True
>    End Function
>
>End Class
>
Gregory
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform