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 !

CRYPTAGE / DECRYPTAGE RC4 POUR VB .NET


Information sur la source

Catégorie :Sécurité Source .NET ( DotNet ) Niveau : Initié Date de création : 04/03/2003 Date de mise à jour : 19/07/2005 22:54:59 Vu : 10 356

Note :
5 / 10 - par 2 personnes
5,00 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10

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

Description

Hello,

J'ai porté en VB .Net la classe de cryptage RC4 de lolo32. J'y ai ajouté quelques fonctionnalités en plus :

-cryptage d'un fichier dans un variable
- cryptage d'un fichier dans un autre fichier

- décryptage d'un fichier dans une variable
- décryptage d'un fichier dans un autre fichier

- génération aléatoire d'une clef de cryptage


 

Source

  • Option Explicit On
  • Imports System.IO
  • Imports System.Text
  • Public Class RC4
  • '/*******************************************/
  • '/* Mise à jour v_1.0.1
  • 'Classe de cryptage réécrite pour VB .NET à partir du code de
  • 'lolo32 (http://www.vbfrance.com/article.aspx?Val=5278)
  • ' Pour toute question dcampillo@gmail.com
  • #Region "Const"
  • Private _version As String = "1.0.1"
  • #End Region
  • #Region "Private var"
  • Private S(255) As Integer
  • Private cls_Key As String
  • #End Region
  • #Region "Property"
  • Public Property Key() As String
  • Get
  • Return cls_Key
  • End Get
  • Set(ByVal Key As String)
  • cls_Key = Key
  • End Set
  • End Property
  • Public ReadOnly Property Version() As String
  • Get
  • Return _version
  • End Get
  • End Property
  • #End Region
  • Public Sub New()
  • End Sub
  • Public Sub New(ByVal Key As String)
  • Me.Key = Key
  • End Sub
  • Public Function Crypt(ByVal Param As String) As String
  • Dim ParamLen As Integer = Param.Length
  • Dim C As Integer
  • Dim T As Integer
  • Dim i As Integer
  • Dim j As Integer
  • Dim oStringBuilder As New StringBuilder
  • CreateKeyArray()
  • For C = 0 To ParamLen - 1
  • i = (i + 1) And 255
  • j = (j + S(i)) And 255
  • T = S(i)
  • S(i) = S(j)
  • S(j) = T
  • T = (S(i) + S(j)) And 255
  • oStringBuilder.Append(Chr(Asc(Param.Substring(C, 1)) Xor S(T)))
  • Next C
  • Return oStringBuilder.ToString
  • End Function
  • Public Overloads Function CryptFile(ByVal FilePath As String) As String
  • Dim oFileInfo As New FileInfo(FilePath)
  • If oFileInfo.Exists Then
  • Dim oFileStream As New FileStream(FilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
  • Dim oFileReader As New StreamReader(oFileStream, System.Text.Encoding.Default)
  • If oFileStream.CanRead Then
  • Dim FileContent As String = oFileReader.ReadToEnd
  • Dim FileLen As Int32 = FileContent.Length
  • Dim C As Integer
  • Dim T As Integer
  • Dim i As Integer
  • Dim j As Integer
  • Dim oStringBuilder As New StringBuilder
  • CreateKeyArray()
  • For C = 0 To FileLen - 1
  • i = (i + 1) And 255
  • j = (j + S(i)) And 255
  • T = S(i)
  • S(i) = S(j)
  • S(j) = T
  • T = (S(i) + S(j)) And 255
  • oStringBuilder.Append(Chr(Asc(FileContent.Substring(C, 1)) Xor S(T)))
  • Next C
  • Return oStringBuilder.ToString
  • Else
  • Throw New Exception("Impossible de lire le fichier " & FilePath)
  • End If
  • Else
  • Throw New Exception("Impossible de trouver le fichier " & FilePath)
  • End If
  • End Function
  • Public Overloads Function CryptFile(ByVal FilePath As String, ByVal OutPutFile As String) As Long
  • Dim oFileInfo As New FileInfo(FilePath)
  • If oFileInfo.Exists Then
  • Dim oFileStream As New FileStream(FilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
  • Dim oFileReader As New StreamReader(oFileStream, System.Text.Encoding.Default)
  • If oFileStream.CanRead Then
  • Dim FileContent As String = oFileReader.ReadToEnd
  • oFileStream.Close()
  • oFileReader.Close()
  • Dim ParamLen As Int32 = FileContent.Length
  • Dim C As Integer
  • Dim T As Integer
  • Dim i As Integer
  • Dim j As Integer
  • Dim oStringBuilder As New StringBuilder
  • CreateKeyArray()
  • For C = 0 To ParamLen - 1
  • i = (i + 1) And 255
  • j = (j + S(i)) And 255
  • T = S(i)
  • S(i) = S(j)
  • S(j) = T
  • T = (S(i) + S(j)) And 255
  • oStringBuilder.Append(Chr(Asc(FileContent.Substring(C, 1)) Xor S(T)))
  • Next C
  • Dim oWriteStream As New FileStream(OutPutFile, FileMode.Create, FileAccess.Write, FileShare.ReadWrite)
  • Dim oFileWriter As New StreamWriter(oWriteStream, System.Text.Encoding.Default)
  • Try
  • oFileWriter.Write(oStringBuilder.ToString)
  • Catch err As Exception
  • Throw New Exception("Impossible d'écrire le fichier de sortie " & OutPutFile)
  • End Try
  • oFileWriter.Close()
  • Return 0
  • Else
  • Throw New Exception("Impossible de lire le fichier " & FilePath)
  • End If
  • Else
  • Throw New Exception("Impossible de trouver le fichier " & FilePath)
  • End If
  • End Function
  • Public Function Decrypt(ByVal Param As String) As String
  • Dim ParamLen As Integer = Len(Param)
  • Dim C As Integer
  • Dim T As Integer
  • Dim i As Integer
  • Dim j As Integer
  • Dim oStringBuilder As New StringBuilder
  • CreateKeyArray()
  • For C = 0 To ParamLen - 1
  • i = (i + 1) And 255
  • j = (j + S(i)) And 255
  • T = S(i)
  • S(i) = S(j)
  • S(j) = T
  • T = (S(i) + S(j)) And 255
  • oStringBuilder.Append(Chr(Asc(Param.Substring(C, 1)) Xor S(T)))
  • Next C
  • Return oStringBuilder.ToString
  • End Function
  • Public Overloads Function DecryptFile(ByVal FilePath As String) As String
  • Dim oFileInfo As New FileInfo(FilePath)
  • If oFileInfo.Exists Then
  • Dim oFileStream As New FileStream(FilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
  • Dim oFileReader As New StreamReader(oFileStream, System.Text.Encoding.Default)
  • If oFileStream.CanRead Then
  • Dim FileContent As String = oFileReader.ReadToEnd
  • Dim FileLen As Int32 = FileContent.Length
  • Dim C As Integer
  • Dim T As Integer
  • Dim i As Integer
  • Dim j As Integer
  • Dim oStringBuilder As New StringBuilder
  • CreateKeyArray()
  • For C = 0 To FileLen - 1
  • i = (i + 1) And 255
  • j = (j + S(i)) And 255
  • T = S(i)
  • S(i) = S(j)
  • S(j) = T
  • T = (S(i) + S(j)) And 255
  • oStringBuilder.Append(Chr(Asc(FileContent.Substring(C, 1)) Xor S(T)))
  • Next C
  • Return oStringBuilder.ToString
  • Else
  • Throw New Exception("Impossible de lire le fichier " & FilePath)
  • End If
  • Else
  • Throw New Exception("Impossible de trouver le fichier " & FilePath)
  • End If
  • End Function
  • Public Overloads Function DecryptFile(ByVal FilePath As String, ByVal OutPutFile As String) As Long
  • Dim oFileInfo As New FileInfo(FilePath)
  • If oFileInfo.Exists Then
  • Dim oFileStream As New FileStream(FilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
  • Dim oFileReader As New StreamReader(oFileStream, System.Text.Encoding.Default)
  • If oFileStream.CanRead Then
  • Dim FileContent As String = oFileReader.ReadToEnd
  • Dim FileLen As Int32 = FileContent.Length
  • Dim C As Integer
  • Dim T As Integer
  • Dim i As Integer
  • Dim j As Integer
  • Dim oStringBuilder As New StringBuilder
  • CreateKeyArray()
  • For C = 0 To FileLen - 1
  • i = (i + 1) And 255
  • j = (j + S(i)) And 255
  • T = S(i)
  • S(i) = S(j)
  • S(j) = T
  • T = (S(i) + S(j)) And 255
  • oStringBuilder.Append(Chr(Asc(FileContent.Substring(C, 1)) Xor S(T)))
  • Next C
  • Dim oWriteStream As New FileStream(OutPutFile, FileMode.Create, FileAccess.Write, FileShare.None)
  • Dim oFileWriter As New StreamWriter(oWriteStream, System.Text.Encoding.Default)
  • Try
  • oFileWriter.Write(oStringBuilder.ToString)
  • Catch err As Exception
  • Throw New Exception("Impossible d'écrire le fichier de sortie " & OutPutFile)
  • End Try
  • oFileWriter.Close()
  • Return 0
  • Else
  • Throw New Exception("Impossible de lire le fichier " & FilePath)
  • End If
  • Else
  • Throw New Exception("Impossible de trouver le fichier " & FilePath)
  • End If
  • End Function
  • Private Sub CreateKeyArray()
  • Dim KeyLen As Integer
  • Dim T As Integer
  • Dim i As Integer = 0
  • Dim j As Integer = 0
  • Dim lItem As Integer
  • If Key.Trim.Length > 0 Then
  • KeyLen = cls_Key.Length
  • For i = 0 To 255
  • S(i) = i
  • Next i
  • For i = 0 To 255
  • j = (j + S(i) + Asc(cls_Key.Substring(i Mod KeyLen, 1)) And 255)
  • T = S(i)
  • S(i) = S(j)
  • S(j) = T
  • Next i
  • i = 0
  • j = 0
  • Else
  • Throw New System.ArgumentException("La clef est vide")
  • End If
  • End Sub
  • Public Overloads Function GenerateKey() As String
  • Dim keyBuffer As New StringBuilder
  • Dim KeyLen As Short = 255
  • Dim i As Integer
  • Randomize(Now.Millisecond)
  • Do Until i >= KeyLen
  • keyBuffer.Append(Chr(CInt(255 * Rnd())))
  • i += 1
  • Loop
  • Me.Key = keyBuffer.ToString
  • Return keyBuffer.ToString
  • End Function
  • Public Overloads Function GenerateKey(ByVal KeyLen As Integer) As String
  • Dim keyBuffer As New StringBuilder
  • Dim i As Integer
  • Randomize(Now.Millisecond)
  • Do Until i >= KeyLen
  • keyBuffer.Append(Chr(CInt(255 * Rnd())))
  • i += 1
  • Loop
  • Me.Key = keyBuffer.ToString
  • Return keyBuffer.ToString
  • End Function
  • Public Overloads Function GenerateKey(ByVal KeyLen As Integer, ByVal Readable As Boolean) As String
  • Dim keyBuffer As New StringBuilder
  • Dim AvailableChar As String = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
  • Dim lenAvailableChar As Integer = AvailableChar.Length - 1
  • Dim i As Integer
  • Randomize(Now.Millisecond)
  • If Readable = True Then
  • Do Until i >= KeyLen
  • keyBuffer.Append(AvailableChar.Substring(CType(lenAvailableChar * Rnd(), Integer), 1))
  • i += 1
  • Loop
  • Else
  • Do Until i >= KeyLen
  • keyBuffer.Append(Chr(CInt(255 * Rnd())))
  • i += 1
  • Loop
  • End If
  • Me.Key = keyBuffer.ToString
  • Return keyBuffer.ToString
  • End Function
  • Public Overloads Function GenerateKey(ByVal KeyLen As Integer, ByVal AvailableChar As String) As String
  • Dim keyBuffer As New StringBuilder
  • Dim lenAvailableChar As Integer = AvailableChar.Length - 1
  • Dim i As Integer
  • Randomize(Now.Millisecond)
  • Do Until i >= KeyLen
  • keyBuffer.Append(AvailableChar.Substring(CType(lenAvailableChar * Rnd(), Integer), 1))
  • i += 1
  • Loop
  • Me.Key = keyBuffer.ToString
  • Return keyBuffer.ToString
  • End Function
  • End Class
Option Explicit On 

Imports System.IO
Imports System.Text

Public Class RC4
    '/*******************************************/
    '/* Mise à jour v_1.0.1

    'Classe de cryptage réécrite pour VB .NET à partir du code de 
    'lolo32 (http://www.vbfrance.com/article.aspx?Val=5278)
    ' Pour toute question dcampillo@gmail.com

#Region "Const"
    Private _version As String = "1.0.1"
#End Region

#Region "Private var"
    Private S(255) As Integer
    Private cls_Key As String
#End Region

#Region "Property"
    Public Property Key() As String
        Get
            Return cls_Key
        End Get
        Set(ByVal Key As String)
            cls_Key = Key
        End Set
    End Property

    Public ReadOnly Property Version() As String
        Get
            Return _version
        End Get
    End Property
#End Region

    Public Sub New()

    End Sub

    Public Sub New(ByVal Key As String)
        Me.Key = Key
    End Sub

    Public Function Crypt(ByVal Param As String) As String
        Dim ParamLen As Integer = Param.Length
        Dim C As Integer
        Dim T As Integer
        Dim i As Integer
        Dim j As Integer

        Dim oStringBuilder As New StringBuilder

        CreateKeyArray()

        For C = 0 To ParamLen - 1
            i = (i + 1) And 255
            j = (j + S(i)) And 255
            T = S(i)
            S(i) = S(j)
            S(j) = T

            T = (S(i) + S(j)) And 255

            oStringBuilder.Append(Chr(Asc(Param.Substring(C, 1)) Xor S(T)))
        Next C

        Return oStringBuilder.ToString
    End Function

    Public Overloads Function CryptFile(ByVal FilePath As String) As String
        Dim oFileInfo As New FileInfo(FilePath)

        If oFileInfo.Exists Then
            Dim oFileStream As New FileStream(FilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
            Dim oFileReader As New StreamReader(oFileStream, System.Text.Encoding.Default)

            If oFileStream.CanRead Then
                Dim FileContent As String = oFileReader.ReadToEnd
                Dim FileLen As Int32 = FileContent.Length
                Dim C As Integer
                Dim T As Integer
                Dim i As Integer
                Dim j As Integer

                Dim oStringBuilder As New StringBuilder

                CreateKeyArray()

                For C = 0 To FileLen - 1
                    i = (i + 1) And 255
                    j = (j + S(i)) And 255
                    T = S(i)
                    S(i) = S(j)
                    S(j) = T

                    T = (S(i) + S(j)) And 255

                    oStringBuilder.Append(Chr(Asc(FileContent.Substring(C, 1)) Xor S(T)))
                Next C

                Return oStringBuilder.ToString
            Else
                Throw New Exception("Impossible de lire le fichier " & FilePath)

            End If
        Else
            Throw New Exception("Impossible de trouver le fichier " & FilePath)
        End If
    End Function

    Public Overloads Function CryptFile(ByVal FilePath As String, ByVal OutPutFile As String) As Long
        Dim oFileInfo As New FileInfo(FilePath)

        If oFileInfo.Exists Then
            Dim oFileStream As New FileStream(FilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
            Dim oFileReader As New StreamReader(oFileStream, System.Text.Encoding.Default)

            If oFileStream.CanRead Then
                Dim FileContent As String = oFileReader.ReadToEnd
                oFileStream.Close()
                oFileReader.Close()

                Dim ParamLen As Int32 = FileContent.Length
                Dim C As Integer
                Dim T As Integer
                Dim i As Integer
                Dim j As Integer

                Dim oStringBuilder As New StringBuilder

                CreateKeyArray()

                For C = 0 To ParamLen - 1
                    i = (i + 1) And 255
                    j = (j + S(i)) And 255
                    T = S(i)
                    S(i) = S(j)
                    S(j) = T

                    T = (S(i) + S(j)) And 255

                    oStringBuilder.Append(Chr(Asc(FileContent.Substring(C, 1)) Xor S(T)))
                Next C

                Dim oWriteStream As New FileStream(OutPutFile, FileMode.Create, FileAccess.Write, FileShare.ReadWrite)
                Dim oFileWriter As New StreamWriter(oWriteStream, System.Text.Encoding.Default)

                Try
                    oFileWriter.Write(oStringBuilder.ToString)
                Catch err As Exception
                    Throw New Exception("Impossible d'écrire le fichier de sortie " & OutPutFile)
                End Try

                oFileWriter.Close()

                Return 0

            Else
                Throw New Exception("Impossible de lire le fichier " & FilePath)
            End If
        Else
            Throw New Exception("Impossible de trouver le fichier " & FilePath)
        End If
    End Function

    Public Function Decrypt(ByVal Param As String) As String



        Dim ParamLen As Integer = Len(Param)
        Dim C As Integer
        Dim T As Integer
        Dim i As Integer
        Dim j As Integer

        Dim oStringBuilder As New StringBuilder

        CreateKeyArray()

        For C = 0 To ParamLen - 1
            i = (i + 1) And 255
            j = (j + S(i)) And 255
            T = S(i)
            S(i) = S(j)
            S(j) = T

            T = (S(i) + S(j)) And 255

            oStringBuilder.Append(Chr(Asc(Param.Substring(C, 1)) Xor S(T)))
        Next C
        Return oStringBuilder.ToString
    End Function

    Public Overloads Function DecryptFile(ByVal FilePath As String) As String

        Dim oFileInfo As New FileInfo(FilePath)

        If oFileInfo.Exists Then
            Dim oFileStream As New FileStream(FilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
            Dim oFileReader As New StreamReader(oFileStream, System.Text.Encoding.Default)

            If oFileStream.CanRead Then
                Dim FileContent As String = oFileReader.ReadToEnd
                Dim FileLen As Int32 = FileContent.Length
                Dim C As Integer
                Dim T As Integer
                Dim i As Integer
                Dim j As Integer

                Dim oStringBuilder As New StringBuilder

                CreateKeyArray()

                For C = 0 To FileLen - 1
                    i = (i + 1) And 255
                    j = (j + S(i)) And 255
                    T = S(i)
                    S(i) = S(j)
                    S(j) = T

                    T = (S(i) + S(j)) And 255

                    oStringBuilder.Append(Chr(Asc(FileContent.Substring(C, 1)) Xor S(T)))
                Next C
                Return oStringBuilder.ToString
            Else
                Throw New Exception("Impossible de lire le fichier " & FilePath)
            End If
        Else
            Throw New Exception("Impossible de trouver le fichier " & FilePath)
        End If
    End Function

    Public Overloads Function DecryptFile(ByVal FilePath As String, ByVal OutPutFile As String) As Long

        Dim oFileInfo As New FileInfo(FilePath)

        If oFileInfo.Exists Then
            Dim oFileStream As New FileStream(FilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
            Dim oFileReader As New StreamReader(oFileStream, System.Text.Encoding.Default)

            If oFileStream.CanRead Then
                Dim FileContent As String = oFileReader.ReadToEnd
                Dim FileLen As Int32 = FileContent.Length
                Dim C As Integer
                Dim T As Integer
                Dim i As Integer
                Dim j As Integer

                Dim oStringBuilder As New StringBuilder

                CreateKeyArray()

                For C = 0 To FileLen - 1
                    i = (i + 1) And 255
                    j = (j + S(i)) And 255
                    T = S(i)
                    S(i) = S(j)
                    S(j) = T

                    T = (S(i) + S(j)) And 255

                    oStringBuilder.Append(Chr(Asc(FileContent.Substring(C, 1)) Xor S(T)))
                Next C

                Dim oWriteStream As New FileStream(OutPutFile, FileMode.Create, FileAccess.Write, FileShare.None)
                Dim oFileWriter As New StreamWriter(oWriteStream, System.Text.Encoding.Default)

                Try
                    oFileWriter.Write(oStringBuilder.ToString)
                Catch err As Exception
                    Throw New Exception("Impossible d'écrire le fichier de sortie " & OutPutFile)
                End Try
                oFileWriter.Close()
                Return 0
            Else
                Throw New Exception("Impossible de lire le fichier " & FilePath)
            End If
        Else
            Throw New Exception("Impossible de trouver le fichier " & FilePath)
        End If
    End Function

    Private Sub CreateKeyArray()
        Dim KeyLen As Integer
        Dim T As Integer
        Dim i As Integer = 0
        Dim j As Integer = 0
        Dim lItem As Integer

        If Key.Trim.Length > 0 Then

            KeyLen = cls_Key.Length

            For i = 0 To 255
                S(i) = i
            Next i

            For i = 0 To 255
                j = (j + S(i) + Asc(cls_Key.Substring(i Mod KeyLen, 1)) And 255)
                T = S(i)
                S(i) = S(j)
                S(j) = T
            Next i
            i = 0
            j = 0
        Else
            Throw New System.ArgumentException("La clef est vide")
        End If

    End Sub

    Public Overloads Function GenerateKey() As String
        Dim keyBuffer As New StringBuilder
        Dim KeyLen As Short = 255
        Dim i As Integer

        Randomize(Now.Millisecond)


        Do Until i >= KeyLen
            keyBuffer.Append(Chr(CInt(255 * Rnd())))
            i += 1
        Loop

        Me.Key = keyBuffer.ToString
        Return keyBuffer.ToString

    End Function

    Public Overloads Function GenerateKey(ByVal KeyLen As Integer) As String
        Dim keyBuffer As New StringBuilder
        Dim i As Integer

        Randomize(Now.Millisecond)

        Do Until i >= KeyLen
            keyBuffer.Append(Chr(CInt(255 * Rnd())))
            i += 1
        Loop

        Me.Key = keyBuffer.ToString
        Return keyBuffer.ToString

    End Function

    Public Overloads Function GenerateKey(ByVal KeyLen As Integer, ByVal Readable As Boolean) As String
        Dim keyBuffer As New StringBuilder
        Dim AvailableChar As String = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
        Dim lenAvailableChar As Integer = AvailableChar.Length - 1
        Dim i As Integer

        Randomize(Now.Millisecond)

        If Readable = True Then
            Do Until i >= KeyLen
                keyBuffer.Append(AvailableChar.Substring(CType(lenAvailableChar * Rnd(), Integer), 1))
                i += 1
            Loop
        Else
            Do Until i >= KeyLen
                keyBuffer.Append(Chr(CInt(255 * Rnd())))
                i += 1
            Loop
        End If
        Me.Key = keyBuffer.ToString
        Return keyBuffer.ToString

    End Function

    Public Overloads Function GenerateKey(ByVal KeyLen As Integer, ByVal AvailableChar As String) As String
        Dim keyBuffer As New StringBuilder
        Dim lenAvailableChar As Integer = AvailableChar.Length - 1
        Dim i As Integer

        Randomize(Now.Millisecond)

        Do Until i >= KeyLen
            keyBuffer.Append(AvailableChar.Substring(CType(lenAvailableChar * Rnd(), Integer), 1))
            i += 1
        Loop

        Me.Key = keyBuffer.ToString
        Return keyBuffer.ToString

    End Function

End Class

Historique

19 juillet 2005 22:54:59 :
Mise à jour version 1.0.1 -------------------------- - Modification du code de la sub CreateKeyArray() - Utilisation des Integer en place des long => Les longs de VB6 sont devenu les integer de .NET ;-) - Modification du code en enlevant toutes les convertions Integer -> Long ou Long -> Integer (le cryptage doit être un poil plus rapide ) ;-) - Ajout d'une propriété Version de type string qui retourne la version de la classe

Commentaires et avis

signaler à un administrateur
Commentaire de stranix le 29/04/2003 18:10:09

Très très bon code.
Mais j'ai remarqué un petit problème. En cas de cryptage de fichier assez volumineux (à partir de 40 Mo), la taille en mémoire de l'éxécutable explose litérallement (j'approche souvent les 300 Mo). Je me dis que c'est peut être normal... mais le problème est qu'une fois le fichier crypté, la taille en mémoire de l'éxécutable ne diminue pas.
Je réalise un programme résident et ce genre de désagrément est assez (voir très) genant. Quelqu'un à une idée pour remédier à ce problème ?
Vous pouvez me répondre via ce site ou via l'adresse gfauvie@goams.com.

signaler à un administrateur
Commentaire de stranix le 07/05/2003 11:06:28

Personne n'a tjs pas d'idée en réponse à mon message précendent ? :(

signaler à un administrateur
Commentaire de Akira le 20/01/2004 23:58:22

Pour eviter de laisser des traces dans la mémoire, detruis les variables complexes telles que : keyBuffer

Si tu déclare une variable avec le mot clef NEW, il te faut la detriure en fin de procédure par un SET keyBuffer = NOTHING

A faire pour toutes les fonctions...

signaler à un administrateur
Commentaire de kore le 11/03/2005 12:36:21

problème sur CryptFile et DecryptFile
ne pas oublier de fermer le fichier source oFileReader.close

signaler à un administrateur
Commentaire de harpa93 le 12/04/2005 17:32:24

Bonjour,
Bravo ton code à l'air très bien, cependant peux-tu m'expliquer comment je peux l'utiliser en VB net à partir d'une form pour crypter et décrypter un fichier xls.
Merci

signaler à un administrateur
Commentaire de harpa93 le 13/04/2005 16:31:30

Rebonjour,

en réfléchissant un petit peu j'ai trouvé moi même pourquoi cela ne fonctionnait pas dans mon code : j'oubliais d'initialiser la key :
  Dim ClassCrypt As New RC4
ClassCrypt.Key = "mon mot de passe"
Encore bravo pour le code, il marche à merveille !

signaler à un administrateur
Commentaire de arnolem le 03/06/2005 11:51:04

moi je ne vois pas comment le faire fonctionner, j'ai une application avec un bouton qui doit crypter un fichier xml et un autre qui doit le charger et le décrypter

signaler à un administrateur
Commentaire de lebender33 le 21/06/2005 16:25:10

Moi non plus je veux juste crypter et décrypter un fichier .txt

signaler à un administrateur
Commentaire de lebender33 le 21/06/2005 16:44:09

A si en fait c'est tout bete
Dim classCrypt As New RC4
        classCrypt.Key = "bender"

        classCrypt.CryptFile("configc.cnf", "config.cnf")

signaler à un administrateur
Commentaire de finrodd le 11/07/2005 18:07:47

Je pense qu'il y a un problème dans la boucle principal de l'algo :

For i = 0 To 255
                S(i) = i --> cette ligne n'a rien a faire ici ?!!
                j = (j + S(i) + Asc(cls_Key.Substring(i Mod KeyLen, 1)) And 255)
                T = S(i)
                S(i) = S(j)
                S(j) = T
Next i

La fonction n'est pas fausse mais beaucoup de S(i) sont écrasés après avoir été calculés...Il faut enlever la ligne

Daniel

signaler à un administrateur
Commentaire de RayBan le 16/07/2005 09:35:40

Entièrement raison... ;-)

Il se peut qu'il y en ait d'autre. La base de la source etaient écrite en VB6, et je l'ai portée pour .NET. Je l'ai testé en long en large mais il y aurait sûrement de quoi l'optimiser. Concerant la ligne, je ferai une mise à jour du source lundi...

Pour la partie cryptage d'un fichier, ce n'est pas le top. Cette portion n'existait pas dans le source vb6. Pour crypter le tout, je charge le contenu du fichier en mémoire (dans une variable), crypte la variable et écrit le contenu dans un fichier de sortie... Pour les gros fichiers, ça génère des problèmes de mémoire. Il faudrait que je me repenche sur la source, pour voir si il est possible de crypter le fichier en direct, mettre le contenu du fichier en mémoire, mais en le cryptant au fur et à mesure de la lecture...

David

signaler à un administrateur
Commentaire de superolive le 30/07/2007 13:49:04

Excellente Source! :P

jen avais justement besoin pour crypter des données clients dans mon applications :)


Bonneprog ;D

signaler à un administrateur
Commentaire de chasseurdedemon le 20/06/2009 00:43:24

bonjour,
le programme ne marche pas
j'ai mi tout le prog dans une classe j'ai bien intensié la classe mais lorsque je fait
RC4.Key = "mot de passe"
RC4.CryptFile("c:\monFichier.ini", "c:\monFichier.ini")
je n'obtient pas mon fichier crypté j'ai toujour monFichier.ini dans c: mais je peux l'ouvrir normalement sans mettrele mot de passe .

quelqu'un peut m'aider merci

signaler à un administrateur
Commentaire de chasseurdedemon le 20/06/2009 12:20:25

personne ne peut répondre à ma question ?

Ajouter un commentaire



Nos sponsors

Sondage...

CalendriCode

Juillet 2009
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
2728293031  

Consulter la suite du CalendriCode

Comparez les prix Nouvelle version

Photothèque Nouveau !



Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés
Temps d'éxécution de la page : 0,328 sec

Google Coop CodeS-SourceS Google Coop CodeS-SourceS


Certaines images présentes sur le site (notament certains avatars) sont issues des collections IconShock, donc si vous souhaitez utiliser ces icons vous devez les acheter, ne les copiez pas et ne utilisez pas dans vos sites et applications sans les avoir commandé.