Public Function Descifrar_AES() As String
Dim contrasena As String = "loco"
Dim cad As String = "l0c0"
Dim algoritmo As String = "sha1"
Dim iteraciones As Integer = 1000
Dim vectorInicial As String = "1234567896541235"
Dim tamanollave As Integer = 256
Try
Dim vectorInicialB As Byte()
vectorInicialB = Encoding.ASCII.GetBytes(vectorInicial)
Dim cadenaB As Byte()
cadenaB = Encoding.ASCII.GetBytes(cad)
Dim textoACifrarB As Byte()
textoACifrarB = Convert.FromBase64String(cadenaCif)
Dim contra As Rfc2898DeriveBytes
contra = New Rfc2898DeriveBytes(contrasena, cadenaB, iteraciones)
Dim llaveB As Byte()
llaveB = contra.GetBytes(tamanollave / 8)
Dim claveSimetrica As RijndaelManaged
claveSimetrica = New RijndaelManaged()
claveSimetrica.Mode = CipherMode.CBC
Dim descifrador As ICryptoTransform
descifrador = claveSimetrica.CreateDecryptor(llaveB, vectorInicialB)
Dim lector As MemoryStream
lector = New MemoryStream(textoACifrarB)
Dim crypto As CryptoStream
crypto = New CryptoStream(lector, descifrador, CryptoStreamMode.Read)
Dim textoPlanoB As Byte()
ReDim textoPlanoB(textoACifrarB.Length)
Dim bytesDesencriptados As Integer
bytesDesencriptados = crypto.Read(textoPlanoB, 0, textoPlanoB.Length)
lector.Close()
crypto.Close()
Dim textoPlano As String
textoPlano = Encoding.UTF8.GetString(textoPlanoB, 0, bytesDesencriptados)
cadena = textoPlano
bError = False
Return cadena
sMsg = "Descifrado Exitoso."
Catch ex As Exception
bError = True
sMsg = "Descifrado fallo: " & ex.Message
Return sMsg
End Try
End Function