begin process at 2008 08 22 05:46:26
1 229 779 membres
50 nouveaux aujourd'hui
14 267 membres club

Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum.
Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !

CHECKSUM SHA1 OU MD5 D'UN FICHIER


Information sur la source

Catégorie :Sécurité Source .NET ( DotNet ) Classé sous : sha1, md5, hash, sum, checksum Niveau : Débutant Date de création : 05/08/2007 Date de mise à jour : 05/08/2007 22:37:21 Vu : 7 993

Note :
9,5 / 10 - par 2 personnes
9,50 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10

Commentaire sur cette source (8)
Ajouter un commentaire et/ou une note

Description

Ces 2 fonctions servent simplement à obtenir la somme de controle SHA1 ou MD5 d'un fichier sans aucune API, exe externe ou autre

Cette source est une traduction VB.net de la source de CrazyHT (http://www.csharpfr.com/codes/SOMME-MD5-FICHIER_11517.aspx)

Source

  • Public Function GetFileMD5CheckSum(ByVal fichier As String) As String
  • If IO.File.Exists(fichier) Then
  • Dim st As System.IO.FileStream = Nothing
  • Try
  • Dim check As New System.Security.Cryptography.MD5CryptoServiceProvider
  • st = System.IO.File.Open(fichier, System.IO.FileMode.Open, System.IO.FileAccess.Read)
  • Dim somme As Byte() = check.ComputeHash(st)
  • Dim ret As String = ""
  • For Each a As Byte In somme
  • If (a < 16) Then
  • ret += "0" + a.ToString("X")
  • Else
  • ret += a.ToString("X")
  • End If
  • Next
  • Return ret
  • Catch ex As Exception
  • Exit Try
  • Finally
  • If st IsNot Nothing Then st.Close()
  • End Try
  • Else
  • Return ""
  • End If
  • Return ""
  • End Function
  • Public Function GetFileSHA1CheckSum(ByVal fichier As String) As String
  • If IO.File.Exists(fichier) Then
  • Dim st As System.IO.FileStream = Nothing
  • Try
  • Dim check As New System.Security.Cryptography.SHA1CryptoServiceProvider
  • st = System.IO.File.Open(fichier, System.IO.FileMode.Open, System.IO.FileAccess.Read)
  • Dim somme As Byte() = check.ComputeHash(st)
  • Dim ret As String = ""
  • For Each a As Byte In somme
  • If (a < 16) Then
  • ret += "0" + a.ToString("X")
  • Else
  • ret += a.ToString("X")
  • End If
  • Next
  • Return ret
  • Catch ex As Exception
  • Exit Try
  • Finally
  • If st IsNot Nothing Then st.Close()
  • End Try
  • Else
  • Return ""
  • End If
  • Return ""
  • End Function
Public Function GetFileMD5CheckSum(ByVal fichier As String) As String
        If IO.File.Exists(fichier) Then
            Dim st As System.IO.FileStream = Nothing
            Try
                Dim check As New System.Security.Cryptography.MD5CryptoServiceProvider
                st = System.IO.File.Open(fichier, System.IO.FileMode.Open, System.IO.FileAccess.Read)
                Dim somme As Byte() = check.ComputeHash(st)
                Dim ret As String = ""
                For Each a As Byte In somme
                    If (a < 16) Then
                        ret += "0" + a.ToString("X")
                    Else
                        ret += a.ToString("X")
                    End If
                Next
                Return ret
            Catch ex As Exception
                Exit Try
            Finally
                If st IsNot Nothing Then st.Close()
            End Try
        Else
            Return ""
        End If
        Return ""
    End Function

    Public Function GetFileSHA1CheckSum(ByVal fichier As String) As String
        If IO.File.Exists(fichier) Then
            Dim st As System.IO.FileStream = Nothing
            Try
                Dim check As New System.Security.Cryptography.SHA1CryptoServiceProvider
                st = System.IO.File.Open(fichier, System.IO.FileMode.Open, System.IO.FileAccess.Read)
                Dim somme As Byte() = check.ComputeHash(st)
                Dim ret As String = ""
                For Each a As Byte In somme
                    If (a < 16) Then
                        ret += "0" + a.ToString("X")
                    Else
                        ret += a.ToString("X")
                    End If
                Next
                Return ret
            Catch ex As Exception
                Exit Try
            Finally
                If st IsNot Nothing Then st.Close()
            End Try
        Else
            Return ""
        End If
        Return ""
    End Function
05 août 2007 14:00:54 :
amélioration de la présentation
05 août 2007 22:37:21 :
mise à jour mineure
  • signaler à un administrateur
    Commentaire de Joke758 le 05/08/2007 22:32:14

    tu me sauve la vie

  • signaler à un administrateur
    Commentaire de allthew3 le 05/08/2007 22:36:24

    de rien alors ^^

  • signaler à un administrateur
    Commentaire de Joke758 le 05/08/2007 22:39:10

    pourrais tu le compiler en dll svp?

  • signaler à un administrateur
    Commentaire de doubledong le 30/09/2007 22:00:27 9/10

    Merci pour ce code, je l'ai utilisé quelques temps mais n'est-ce pas plus simple de faire :
                Dim f As FileStream = New FileStream(fichier, FileMode.Open, FileAccess.Read, FileShare.Read, 8192)
                Dim md5 As New MD5CryptoServiceProvider
                md5.ComputeHash(f)
                f.Close()
                Dim hash As New StringBuilder
                For Each a As Byte In md5.Hash
                    hash.Append(String.Format("{0:X1}", a))
                Next
    ?

  • signaler à un administrateur
    Commentaire de allthew3 le 01/10/2007 15:34:00

    Si ton code est plus simple, mais pour ma part j'avais juste traduit une source C#, j'ai pas cherché à l'amélioré (j'étais pressé par le temps)

    Merci de l'avoir mis en commentaire ^^ : avis aux amateurs :P

    et Merci pour la note @+

  • signaler à un administrateur
    Commentaire de Mario1095 le 17/02/2008 08:07:42

    Cool

  • signaler à un administrateur
    Commentaire de Mario1095 le 17/02/2008 08:10:40

    Je me demande comment ta fais mais t'es for en tout cas !

  • signaler à un administrateur
    Commentaire de allthew3 le 17/02/2008 11:23:51

    merci :P

Ajouter un commentaire

Discussions en rapport avec ce code source

Pub



Appels d'offres

CalendriCode

Août 2008
LMMJVSD
    123
45678910
11121314151617
18192021222324
25262728293031

Téléchargements

Logiciels à télécharger sur le même thème :

Boutique

Boutique de goodies CodeS-SourceS