IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VB.NET Discussion :

RSA Cryptage/Décryptage des String


Sujet :

VB.NET

  1. #1
    Nouveau membre du Club
    Profil pro
    Poste x dans une société
    Inscrit en
    Mars 2007
    Messages
    27
    Détails du profil
    Informations personnelles :
    Localisation : Algérie

    Informations professionnelles :
    Activité : Poste x dans une société

    Informations forums :
    Inscription : Mars 2007
    Messages : 27
    Points : 38
    Points
    38
    Par défaut RSA Cryptage/Décryptage des String
    Bonjour à tous
    Ben j'utilise l'algorithme RSA pour crypter des chaines String et les insérer dans une BD SQLServer 2000 , mais le probleme se pose dans le codage à choisir
    voici mon code :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
     
    Public Function RSAEncrypt(ByVal DataToEncrypt As Byte(), ByVal RSAKeyInfo As RSAParameters, ByVal DoOAEPPadding As Boolean) As Byte()
            'Cryptage RSA source : ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1036/cpref/html/frlrfSystemSecurityCryptographyRSACryptoServiceProviderClassTopic.htm
            Try
                'Create a new instance of RSACryptoServiceProvider.
                Dim RSA As New RSACryptoServiceProvider
                'Import the RSA Key information. This only needs
                'toinclude the public key information.
                RSA.ImportParameters(RSAKeyInfo)
     
                'Encrypt the passed byte array and specify OAEP padding.  
                'OAEP padding is only available on Microsoft Windows XP or
                'later.  
                Return RSA.Encrypt(DataToEncrypt, DoOAEPPadding)
            Catch ex As Exception
                Return Nothing
            End Try
    End Function
     
     Public Function RSADecrypt(ByVal DataToDecrypt As Byte(), ByVal RSAKeyInfo As RSAParameters, ByVal DoOAEPPadding As Boolean) As Byte()
            'Décryptage RSA source : ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1036/cpref/html/frlrfSystemSecurityCryptographyRSACryptoServiceProviderClassTopic.htm
            Try
                'Create a new instance of RSACryptoServiceProvider.
                Dim RSA As New RSACryptoServiceProvider
                'Import the RSA Key information. This needs
                'to include the private key information.
                RSA.ImportParameters(RSAKeyInfo)
                'Decrypt the passed byte array and specify OAEP padding.  
                'OAEP padding is only available on Microsoft Windows XP or
                'later.  
                Return RSA.Decrypt(DataToDecrypt, DoOAEPPadding)
     
            Catch ex As Exception
                Return Nothing
            End Try
     
     
        End Function
    Exemple d'utilisation :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
     
     Dim ByteConverter As New UTF8Encoding
            Dim dataToEncrypt As Byte() = ByteConverter.GetBytes("usmhBvB")
            Dim encryptedData As Byte()
            Dim decryptedData As Byte()
     
    Dim RSA As New RSACryptoServiceProvider
                encryptedData = RSAEncrypt(dataToEncrypt, RSA.ExportParameters(False), False)
                Dim chaine_crypte = ByteConverter.GetString(encryptedData)
                decryptedData = RSADecrypt(encryptedData, RSA.ExportParameters(True), False)
                Dim chaine_decrypte As String = ByteConverter.GetString(decryptedData)
    je veut crypter avec RSA et je voudrai avoir des chaines cryptées ne contiennent que des caractères Alphanumérique ! Est ce que c'est possible ? Merci

  2. #2
    Membre régulier Avatar de grrrkewel
    Profil pro
    Inscrit en
    Juillet 2008
    Messages
    72
    Détails du profil
    Informations personnelles :
    Âge : 39
    Localisation : France

    Informations forums :
    Inscription : Juillet 2008
    Messages : 72
    Points : 75
    Points
    75
    Par défaut
    Hello,

    As-tu cherché un cours sur le cryptosystème RSA? ça pourrai répondre à ta question... je dois avouer que mes cours de crypto sont un peu loin, donc à froid je pourrais pas te donner la réponse, mais avec un bon cours... (cf google)

    GrrrK.
    Si ma réponse est erronée, ignorez là, mais au moins j'aurais essayé
    Il n'y a pas de mauvaise question, si quelqu'un se la pose, ça ne doit pas être le seul

  3. #3
    Rédacteur/Modérateur


    Homme Profil pro
    Développeur .NET
    Inscrit en
    Février 2004
    Messages
    19 875
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 42
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Février 2004
    Messages : 19 875
    Points : 39 749
    Points
    39 749
    Par défaut
    tu peux convertir ton tableau de byte en chaîne hexadécimale :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    Public Sub ByteArrayToHexString(bytes as Byte()) As String
        Dim sb As New StringBuilder()
        For i = 0 To bytes.Length
            sb.AppendFormat("{0:X2}", bytes(i))
        Next i
        Return sb.ToString()
    End Sub
    Tu peux aussi le mettre en base 64, avec la méthode Convert.ToBase64String

  4. #4
    Nouveau membre du Club
    Profil pro
    Poste x dans une société
    Inscrit en
    Mars 2007
    Messages
    27
    Détails du profil
    Informations personnelles :
    Localisation : Algérie

    Informations professionnelles :
    Activité : Poste x dans une société

    Informations forums :
    Inscription : Mars 2007
    Messages : 27
    Points : 38
    Points
    38
    Par défaut Merci Beaucoup

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [Lazarus] Passer des strings à un algorithme de cryptage
    Par philgre dans le forum Lazarus
    Réponses: 1
    Dernier message: 11/03/2012, 20h24
  2. Problème de cryptage/décryptage DES
    Par Kaneda Shotaro dans le forum C#
    Réponses: 5
    Dernier message: 26/06/2011, 14h00
  3. Algorithme de cryptage décryptage RSA
    Par ISIL3EME dans le forum Sécurité
    Réponses: 4
    Dernier message: 26/07/2010, 15h22
  4. Problème de cryptage/décryptage RSA en Java
    Par Reeter dans le forum Sécurité
    Réponses: 2
    Dernier message: 29/03/2009, 22h41

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo