VB.NET: Problème avec les accents AES-128
Résolu/Fermé
Anonyme209
Messages postés
679
Date d'inscription
samedi 6 octobre 2012
Statut
Membre
Dernière intervention
22 décembre 2020
-
17 déc. 2014 à 09:34
Anonyme209 Messages postés 679 Date d'inscription samedi 6 octobre 2012 Statut Membre Dernière intervention 22 décembre 2020 - 17 déc. 2014 à 20:39
Anonyme209 Messages postés 679 Date d'inscription samedi 6 octobre 2012 Statut Membre Dernière intervention 22 décembre 2020 - 17 déc. 2014 à 20:39
A voir également:
- VB.NET: Problème avec les accents AES-128
- 128 gb en go ✓ - Forum Matériel informatique
- E avec accent - Guide
- Mémoire vidéo dédiée : 128 mo ✓ - Forum Carte graphique
- Les accents sont remplacés par des caractères ✓ - Forum Programmation
- Comment mettre les accents avec un clavier qwerty ✓ - Forum Windows
4 réponses
NHenry
Messages postés
15047
Date d'inscription
vendredi 14 mars 2003
Statut
Modérateur
Dernière intervention
11 mars 2023
331
17 déc. 2014 à 12:06
17 déc. 2014 à 12:06
Quelle version de VB ?
En VB.NET, au lieu de prendre System.Test.Encoding.ASCII, utilises UTF8
En VB.NET, au lieu de prendre System.Test.Encoding.ASCII, utilises UTF8
Anonyme209
Messages postés
679
Date d'inscription
samedi 6 octobre 2012
Statut
Membre
Dernière intervention
22 décembre 2020
19
17 déc. 2014 à 13:39
17 déc. 2014 à 13:39
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
NHenry
Messages postés
15047
Date d'inscription
vendredi 14 mars 2003
Statut
Modérateur
Dernière intervention
11 mars 2023
331
17 déc. 2014 à 18:35
17 déc. 2014 à 18:35
System.Text.ASCIIEncoding.ASCII c'est la même chose que System.Text.Encoding.ASCII
cs_Le Pivert
Messages postés
7883
Date d'inscription
jeudi 13 septembre 2007
Statut
Contributeur
Dernière intervention
18 mars 2023
724
17 déc. 2014 à 18:19
17 déc. 2014 à 18:19
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
Anonyme209
Messages postés
679
Date d'inscription
samedi 6 octobre 2012
Statut
Membre
Dernière intervention
22 décembre 2020
19
17 déc. 2014 à 20:39
17 déc. 2014 à 20:39
Merci,
avec ce code les accents sont affichés correctement même après le décryptage.
avec ce code les accents sont affichés correctement même après le décryptage.