elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Guía rápida para descarga de herramientas gratuitas de seguridad y desinfección


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  .NET (C#, VB.NET, ASP) (Moderador: kub0x)
| | | |-+  descifrar AES en vb.net?
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: descifrar AES en vb.net?  (Leído 4,987 veces)
<housedir>

Desconectado Desconectado

Mensajes: 199



Ver Perfil
descifrar AES en vb.net?
« 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


En línea

Titulo: Padre nuestro
Padre Nuestro que estás en www.cielo.com
Santificado sea tu server, venga a nosotros tu shareware
Hágase tu downloading así en el http como en el ftp
Danos hoy nuestro surfing de cada día,
Perdona nuestros bugs
como nosotros también perdonamos a Microsoft.
No nos dejes caer en una Mac y líbranos de todo worm.
Enter...
Eleкtro
Ex-Staff
*
Desconectado Desconectado

Mensajes: 9.813



Ver Perfil
Re: descifrar AES en vb.net?
« Respuesta #1 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)


En línea

<housedir>

Desconectado Desconectado

Mensajes: 199



Ver Perfil
Re: descifrar AES en vb.net?
« Respuesta #2 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)

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...
En línea

Titulo: Padre nuestro
Padre Nuestro que estás en www.cielo.com
Santificado sea tu server, venga a nosotros tu shareware
Hágase tu downloading así en el http como en el ftp
Danos hoy nuestro surfing de cada día,
Perdona nuestros bugs
como nosotros también perdonamos a Microsoft.
No nos dejes caer en una Mac y líbranos de todo worm.
Enter...
Keyen Night


Desconectado Desconectado

Mensajes: 496


Nothing


Ver Perfil
Re: descifrar AES en vb.net?
« Respuesta #3 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.
En línea

La Fé Mueve Montañas...
                                    ...De Dinero

La programación es más que un trabajo es más que un hobby es una pasión...
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines