VB.NET: Problème avec les accents AES-128
Résolu
Anonyme209
Messages postés
681
Date d'inscription
Statut
Membre
Dernière intervention
-
Anonyme209 Messages postés 681 Date d'inscription Statut Membre Dernière intervention -
Anonyme209 Messages postés 681 Date d'inscription Statut Membre Dernière intervention -
Bonjour,
Pour crypter des données sur Visual Basic, j'utilise souvent l'algorithme AES (128 bits).
Mais j'ai remarqué que les accents s'affichaient "?" lors du décryptage.
J'aimerais savoir comment faire pour éviter cela.
Merci de votre aide.
Pour crypter des données sur Visual Basic, j'utilise souvent l'algorithme AES (128 bits).
Mais j'ai remarqué que les accents s'affichaient "?" lors du décryptage.
J'aimerais savoir comment faire pour éviter cela.
Merci de votre aide.
A voir également:
- VB.NET: Problème avec les accents AES-128
- Vb.net express - Télécharger - Langages
- Vb.net - Télécharger - Langages
- Convert | VB.net ✓ - Forum Framework .NET
- Vb.net editor - Télécharger - Langages
- Listview vb.net ✓ - Forum Framework .NET
4 réponses
C'est du VB.NET
Je n'ai pas trouvé "System.Text.Encoding.ASCII" ou "System.Text.Encoding.ASCII" dans les fonctions AES_Encrypt ou AES_Decrypt.
Peut-être que ma fonction n'est pas correcte.
Dans ce cas laquelle dois-je utiliser?
Je n'ai pas trouvé "System.Text.Encoding.ASCII" ou "System.Text.Encoding.ASCII" dans les fonctions AES_Encrypt ou AES_Decrypt.
Peut-être que ma fonction n'est pas correcte.
Dans ce cas laquelle dois-je utiliser?
Public Function AES_Encrypt(ByVal input As String, ByVal pass As String) As String Dim AES As New System.Security.Cryptography.RijndaelManaged Dim Hash_AES As New System.Security.Cryptography.MD5CryptoServiceProvider Dim encrypted As String = "" Try Dim hash(31) As Byte Dim temp As Byte() = Hash_AES.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(pass)) Array.Copy(temp, 0, hash, 0, 16) Array.Copy(temp, 0, hash, 15, 16) AES.Key = hash AES.Mode = Security.Cryptography.CipherMode.ECB Dim DESEncrypter As System.Security.Cryptography.ICryptoTransform = AES.CreateEncryptor Dim Buffer As Byte() = System.Text.ASCIIEncoding.ASCII.GetBytes(input) encrypted = Convert.ToBase64String(DESEncrypter.TransformFinalBlock(Buffer, 0, Buffer.Length)) Return encrypted Catch ex As Exception End Try End Function Public Function AES_Decrypt(ByVal input As String, ByVal pass As String) As String Dim AES As New System.Security.Cryptography.RijndaelManaged Dim Hash_AES As New System.Security.Cryptography.MD5CryptoServiceProvider Dim decrypted As String = "" Try Dim hash(31) As Byte Dim temp As Byte() = Hash_AES.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(pass)) Array.Copy(temp, 0, hash, 0, 16) Array.Copy(temp, 0, hash, 15, 16) AES.Key = hash AES.Mode = Security.Cryptography.CipherMode.ECB Dim DESDecrypter As System.Security.Cryptography.ICryptoTransform = AES.CreateDecryptor Dim Buffer As Byte() = Convert.FromBase64String(input) decrypted = System.Text.ASCIIEncoding.ASCII.GetString(DESDecrypter.TransformFinalBlock(Buffer, 0, Buffer.Length)) Return decrypted Catch ex As Exception End Try End Function
Bonjour,
Voici avec les caractères accentués:
Voici avec les caractères accentués:
Imports System.IO Imports System.Text Public Class Form1 Dim strContent As String Dim path As String = "C:\Users\Daniel\Documents\MyTest.txt" 'a adapter Public Function AES_Encrypt(ByVal input As String, ByVal pass As String) As String Dim AES As New System.Security.Cryptography.RijndaelManaged Dim Hash_AES As New System.Security.Cryptography.MD5CryptoServiceProvider Dim encrypted As String = "" Try Dim hash(31) As Byte Dim temp As Byte() = Hash_AES.ComputeHash(System.Text.Encoding.Default.GetBytes(pass)) Array.Copy(temp, 0, hash, 0, 16) Array.Copy(temp, 0, hash, 15, 16) AES.Key = hash AES.Mode = Security.Cryptography.CipherMode.ECB Dim DESEncrypter As System.Security.Cryptography.ICryptoTransform = AES.CreateEncryptor Dim Buffer As Byte() = System.Text.Encoding.Default.GetBytes(input) encrypted = Convert.ToBase64String(DESEncrypter.TransformFinalBlock(Buffer, 0, Buffer.Length)) Return encrypted Catch ex As Exception Return Nothing End Try End Function Public Function AES_Decrypt(ByVal input As String, ByVal pass As String) As String Dim AES As New System.Security.Cryptography.RijndaelManaged Dim Hash_AES As New System.Security.Cryptography.MD5CryptoServiceProvider Dim decrypted As String = "" Try Dim hash(31) As Byte Dim temp As Byte() = Hash_AES.ComputeHash(System.Text.Encoding.Default.GetBytes(pass)) Array.Copy(temp, 0, hash, 0, 16) Array.Copy(temp, 0, hash, 15, 16) AES.Key = hash AES.Mode = Security.Cryptography.CipherMode.ECB Dim DESDecrypter As System.Security.Cryptography.ICryptoTransform = AES.CreateDecryptor Dim Buffer As Byte() = Convert.FromBase64String(input) decrypted = System.Text.Encoding.Default.GetString(DESDecrypter.TransformFinalBlock(Buffer, 0, Buffer.Length)) Return decrypted Catch ex As Exception Return Nothing End Try End Function Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click strContent = "éèàaztocéà" strContent = AES_Encrypt(strContent, "somepassword") File.WriteAllText(path, strContent) End Sub Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click strContent = "DeSIW7QBVFGZYY/PFjOvpA==" strContent = AES_Decrypt(strContent, "somepassword") File.WriteAllText(path, strContent) End Sub End Class