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