Título: descifrar AES en vb.net?
Publicado por: <housedir> en 15 Agosto 2013, 10:59 am
hola a todos, quisiera que me ayudaran a descifrar AES en vb.net, lo he logrado hacer en PHP pero en vb.net ademas de pedirme el codigo a descifrar, y la key, me pide un salt (cosa que PHP parece que genera automaticamente), la key que tiene el texto que quiero descifrar es de 32 carapteres, aqui muestro un codigo que uso pero que siempre me lanza error y es por el salt: Public Function Decrypt(ByVal encryptedBytes As String, ByVal secretKey As String) As String Dim plainText As String = Nothing Using inputStream As MemoryStream = New MemoryStream(Convert.FromBase64String(encryptedBytes)) Dim algorithm As RijndaelManaged = getAlgorithm(secretKey) Using cryptoStream As CryptoStream = New CryptoStream(inputStream, algorithm.CreateDecryptor(), CryptoStreamMode.Read) Dim outputBuffer(0 To CType(inputStream.Length - 1, Integer)) As Byte Dim readBytes As Integer = cryptoStream.Read(outputBuffer, 0, CType(inputStream.Length, Integer)) plainText = Encoding.Unicode.GetString(outputBuffer, 0, readBytes) End Using End Using Return plainText End Function
Private Function getAlgorithm(ByVal secretKey As String) As RijndaelManaged Const salt As String = "aqui el salt" Const keySize As Integer = 256
Dim keyBuilder As Rfc2898DeriveBytes = New Rfc2898DeriveBytes(secretKey, Encoding.Unicode.GetBytes(salt)) Dim algorithm As RijndaelManaged = New RijndaelManaged() algorithm.KeySize = keySize algorithm.IV = keyBuilder.GetBytes(CType(algorithm.BlockSize / 8, Integer)) algorithm.Key = keyBuilder.GetBytes(CType(algorithm.KeySize / 8, Integer)) algorithm.Padding = PaddingMode.PKCS7 Return algorithm End Function
increiblemente, no consigo un codigo que desencripte el texto que tengo, cuando hasta una web online lo desencipta solo con el texto y la key, espero me puedan ayudar, gracias
Título: Re: descifrar AES en vb.net?
Publicado por: Eleкtro en 15 Agosto 2013, 14:59 pm
Prueba así, este no pide el salt: #Region " AES Decrypt " ' [ AES Decrypt Function ] ' ' Examples : ' MsgBox(AES_Decrypt("cv/vYwpl51/dxbxSMNSPSg==", "Test_Password")) ' Result: Test_Text 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 Return Nothing End Try End Function #End Region
...Aquí el encriptador, y más snippets: Librería de Snippets !! (Posteen aquí sus snippets) (http://foro.elhacker.net/net/libreria_de_snippets_posteen_aqui_sus_snippets-t378770.0.html)
Título: Re: descifrar AES en vb.net?
Publicado por: <housedir> en 15 Agosto 2013, 18:08 pm
Prueba así, este no pide el salt: #Region " AES Decrypt " ' [ AES Decrypt Function ] ' ' Examples : ' MsgBox(AES_Decrypt("cv/vYwpl51/dxbxSMNSPSg==", "Test_Password")) ' Result: Test_Text 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 Return Nothing End Try End Function #End Region
...Aquí el encriptador, y más snippets: Librería de Snippets !! (Posteen aquí sus snippets) (http://foro.elhacker.net/net/libreria_de_snippets_posteen_aqui_sus_snippets-t378770.0.html) gracias por tu respuesta, ese ya lo probe tambien me dice "El relleno entre caracteres no es válido y no se puede quitar." el error sucede aqui: decrypted = System.Text.ASCIIEncoding.ASCII.GetString(DESDecrypter.TransformFinalBlock(Buffer, 0, Buffer.Length)) ese es el mismo error que lanza el otro codigo, si quieres probar puedes usar esto para probar: Dim codigo As String = "U2FsdGVkX1/2yL/ez3xEXU4zKH4azlVQ+kPUI4qyG0wZQnwtE9/SKHMeTZRHFy1+R5+we5jxYvrD8O2OfBYJTw=="
Dim key As String = "9c8b1724a3a293207d87c7c24e1733b4"
TextBox2.Text = AES_Decrypt(codigo, key)
Debe devolverte una URL, si me podrias ayudar te lo agradeceria muchisimo...
Título: Re: descifrar AES en vb.net?
Publicado por: Keyen Night en 19 Agosto 2013, 02:22 am
Esa es una pobre definición de la implementación del algoritmo, te recomendaría buscar una buena definición de como se utilizan los algoritmos de cifrado simétrico en .Net que de hecho todos tienen la misma metodología.
|