Foro de elhacker.net

Programación => .NET (C#, VB.NET, ASP) => Mensaje iniciado por: <housedir> en 15 Agosto 2013, 10:59 am



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:

Código:
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:

Código
  1.    #Region " AES Decrypt "
  2.  
  3.       ' [ AES Decrypt Function ]
  4.       '
  5.       ' Examples :
  6.       ' MsgBox(AES_Decrypt("cv/vYwpl51/dxbxSMNSPSg==", "Test_Password")) ' Result: Test_Text
  7.  
  8.       Public Function AES_Decrypt(ByVal input As String, ByVal pass As String) As String
  9.           Dim AES As New System.Security.Cryptography.RijndaelManaged
  10.           Dim Hash_AES As New System.Security.Cryptography.MD5CryptoServiceProvider
  11.           Dim decrypted As String = ""
  12.           Try
  13.               Dim hash(31) As Byte
  14.               Dim temp As Byte() = Hash_AES.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(pass))
  15.               Array.Copy(temp, 0, hash, 0, 16)
  16.               Array.Copy(temp, 0, hash, 15, 16)
  17.               AES.Key = hash
  18.               AES.Mode = Security.Cryptography.CipherMode.ECB
  19.               Dim DESDecrypter As System.Security.Cryptography.ICryptoTransform = AES.CreateDecryptor
  20.               Dim Buffer As Byte() = Convert.FromBase64String(input)
  21.               decrypted = System.Text.ASCIIEncoding.ASCII.GetString(DESDecrypter.TransformFinalBlock(Buffer, 0, Buffer.Length))
  22.               Return decrypted
  23.           Catch ex As Exception
  24.               Return Nothing
  25.           End Try
  26.       End Function
  27.  
  28.    #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:

Código
  1.    #Region " AES Decrypt "
  2.  
  3.       ' [ AES Decrypt Function ]
  4.       '
  5.       ' Examples :
  6.       ' MsgBox(AES_Decrypt("cv/vYwpl51/dxbxSMNSPSg==", "Test_Password")) ' Result: Test_Text
  7.  
  8.       Public Function AES_Decrypt(ByVal input As String, ByVal pass As String) As String
  9.           Dim AES As New System.Security.Cryptography.RijndaelManaged
  10.           Dim Hash_AES As New System.Security.Cryptography.MD5CryptoServiceProvider
  11.           Dim decrypted As String = ""
  12.           Try
  13.               Dim hash(31) As Byte
  14.               Dim temp As Byte() = Hash_AES.ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(pass))
  15.               Array.Copy(temp, 0, hash, 0, 16)
  16.               Array.Copy(temp, 0, hash, 15, 16)
  17.               AES.Key = hash
  18.               AES.Mode = Security.Cryptography.CipherMode.ECB
  19.               Dim DESDecrypter As System.Security.Cryptography.ICryptoTransform = AES.CreateDecryptor
  20.               Dim Buffer As Byte() = Convert.FromBase64String(input)
  21.               decrypted = System.Text.ASCIIEncoding.ASCII.GetString(DESDecrypter.TransformFinalBlock(Buffer, 0, Buffer.Length))
  22.               Return decrypted
  23.           Catch ex As Exception
  24.               Return Nothing
  25.           End Try
  26.       End Function
  27.  
  28.    #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:

Código:
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:

Código:
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.