murdoch201
Gebruiker
- Lid geworden
- 31 mei 2008
- Berichten
- 336
Hoi,
Ik heb hier een stuk code voor een encryptie toe te passen op een string in VB.NET. Ik heb reeds geprobeerd om de code om te zetten naar VB6, maar heb een beetje moeite.
De originele code:
De code voor VB6 (tot nu toe):
Wat doe ik met Array.copy? Die functie bestaat niet in VB6. En volgens mij gaat System.* ook niet werken, wat gebruik ik in de plaats? En ziet deze code er verder goed uit?
Alvast bedankt!
Groetjes,
murdoch
Ik heb hier een stuk code voor een encryptie toe te passen op een string in VB.NET. Ik heb reeds geprobeerd om de code om te zetten naar VB6, maar heb een beetje moeite.
De originele code:
Code:
Module AESstring
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
End Module
De code voor VB6 (tot nu toe):
Code:
Public Function AES_Encrypt(ByVal inputt 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
encrpyted = ""
On Error GoTo notifyy:
Dim hash(31) As Byte
Dim temp As Byte
temp = Hash_AES.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(pass))
copyarray (temp), 0, hash, 0, 16
copyarray (temp), 0, hash, 15, 16
a
AES.Key = hash
AES.Mode = Security.Cryptography.CipherMode.ECB
Dim DESEncrypter As System.Security.Cryptography.ICryptoTransform
DESEncrypter = AES.CreateEncryptor
Dim Buffer As Byte
Buffer = System.Text.ASCIIEncoding.ASCII.GetBytes(inputt)
encrypted = Convert.ToBase64String(DESEncrypter.TransformFinalBlock(Buffer, 0, Buffer.Length))
AES_Encrypt = encrypted
End Function
Public Function AES_Decrypt(ByVal inputt 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
decrypted = ""
On Error GoTo notifyy:
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))
AES_Decrypt = decrypted
End Function
notifyy:
Form1.logadd ("red"), "Error occured somewhere when encrypting/decrypting"
Wat doe ik met Array.copy? Die functie bestaat niet in VB6. En volgens mij gaat System.* ook niet werken, wat gebruik ik in de plaats? En ziet deze code er verder goed uit?
Alvast bedankt!

Groetjes,
murdoch