Visual Basic.NET - Desencriptar texto

 
Vista:

Desencriptar texto

Publicado por Maria (10 intervenciones) el 23/07/2007 15:20:27
Buenas tardes a todos/as!

Hace unos días un compañero de este foro 'Harold' me dió una función para encriptar texto, pero no me dió la opción de desencriptar. La necesito para poder mostrar la información desencriptada de la base de datos que se guarda encriptada.

Os remito la función, a ver si alguien sabe hacer la función de desencriptar.

Muchas gracias de antemano,

María.

--- Clase Login --------------------------------------------------------------------

Imports System.Security.Cryptography

Public Class Login

Public Sub New()

End Sub

Public Function EncriptPassword(ByVal password As String) As String
If password = "" Then
Return Nothing
Exit Function
End If

Dim bytPassword(), bytEncrypted() As Byte
Dim strEncryptedPassword As String = ""
Dim sec As New SHA1CryptoServiceProvider
Dim ue As New System.Text.UTF8Encoding
Dim PassEncrypted As String = ""
Try
bytPassword = ue.GetBytes(password)
bytEncrypted = sec.ComputeHash(bytPassword)
PassEncrypted = Convert.ToBase64String(bytEncrypted)
Catch exc As Exception
MsgBox("Un error ha ocurrido en la encriptación.")
End Try
Return PassEncrypted
End Function

End Class
--------------------------------------------------------------------
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:Desencriptar texto

Publicado por QWNET (65 intervenciones) el 23/07/2007 18:27:26
'Bueno maria esto te paso Harold hace unos dias me llamo la atencion y lo estuve probando y pues si funciona bien tanto la incriptacion como la desencriptacion asi que aqui te lo replico.

Imports System.Security.Cryptography

Dim sec As New RSACryptoServiceProvider
Dim bytString(), bytEncrypted(), bytDesencrypted() As Byte
Dim ue As New System.Text.UTF8Encoding

Dim Encrypted As String = ""
Dim Desencrypted As String = ""
Dim strEncryptedPassword As String = ""

Public Function Encriptar(ByVal EncriptString As String) As String
If EncriptString = "" Then
Return Nothing
Exit Function
End If
Try
bytString = ue.GetBytes(EncriptString)
bytEncrypted = sec.Encrypt(bytString, False)
Encrypted = Convert.ToBase64String(bytEncrypted)
Catch exc As Exception
MsgBox("Un error ha ocurrido en la encriptación.")
End Try
Return Encrypted

End Function

Public Function Desencriptar(ByVal TextEncripted As String) As String
If TextEncripted = "" Then
Return Nothing
Exit Function
End If
Try
bytDesencrypted = sec.Decrypt(Convert.FromBase64String(TextEncripted), False)
Desencrypted = ue.GetString(bytDesencrypted)
Catch exc As Exception
MsgBox("Un error ha ocurrido en la desencriptación.")
End Try
Return Desencrypted

End Function

Private Sub btnEncriptar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEncriptar.Click
txtResultado.Text = Encriptar(txtEncriptar.Text)
End Sub

Private Sub btnDesencriptar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDesencriptar.Click
txtDesencriptado.Text = Desencriptar(txtResultado.Text)
End Sub
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:Desencriptar texto

Publicado por Maria (10 intervenciones) el 24/07/2007 08:17:47
'A mi sigue sin funcionarme, he ido probando diferentes versiones de los mismo y cuando hago el desencriptar me devuelve algo raro. Te explico con más detalle:

'Guardo en un fichero config.ini el nombre de usuario y su correspondiente password, todo encriptado la primera vez que se logean correctamente.

'Hay una opción para guardar el usuario y el password que se cargará automáticamente cada vez que el usuario ejecute la aplicación.

Ejemplo: usuario & password: maria
Encriptado: 4h/FbBonK2MODRQ5B50FmM+Lgyk=
Desencriptado: a#%pUA~Bz

--------------------------------- ClassLogin ---------------------------------
Imports System.Security.Cryptography
Public Class ClassLogin

Dim sec As New SHA1CryptoServiceProvider
Dim bytString(), bytEncrypted(), bytDesencrypted() As Byte
Dim ue As New System.Text.UTF8Encoding
Dim Encrypted As String = "" : Dim Desencrypted As String = ""

Public Function Encriptar(ByVal EncriptString As String) As String
If EncriptString = "" Then
Return Nothing
Exit Function
End If
Try
bytString = ue.GetBytes(EncriptString)
bytEncrypted = sec.ComputeHash(bytString)
Encrypted = Convert.ToBase64String(bytEncrypted)
Catch exc As Exception
MessageBox.Show("Un error ha ocurrido en la encriptación.", "Error al Encriptar", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
Return Encrypted
End Function

Public Function Desencriptar(ByVal TextEncripted As String) As String
If TextEncripted = "" Then
Return Nothing
Exit Function
End If
Try
bytDesencrypted = sec.ComputeHash(Convert.FromBase64String(TextEncripted))
Desencrypted = ue.GetString(bytDesencrypted)
Catch exc As Exception
MessageBox.Show("Un error ha ocurrido en la desencriptación.", "Error al Desencriptar", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
Return Desencrypted
End Function

End Class
---------------------------------------------------------------------------------------------------

---------------------------------frmUsuario-------------------------------------------
Encriptar: password = ClassLogin.Encriptar(Me.txtPassword.Text)

Desencriptar: Me.txtPassword.Text = ClassLogin.Desencriptar(Configuration.sPass)

La variable Configuration.sPass he comprobado que vale: 4h/FbBonK2MODRQ5B50FmM+Lgyk=
y lee del fichero config.ini donde se guarda el password.
---------------------------------------------------------------------------------------------------

Alguna razón porque no desencripte bien? la variable es string, y el valor es el mismo entonces no puedo adivinar el porque.

Muchas graciasssssssssssssss por la paciencia.

Maria.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:Desencriptar texto

Publicado por Harold V. (411 intervenciones) el 24/07/2007 13:48:32
Maria:

El SHA1CryptoServiceProvider es solo de ida, osea que solo lo puedes encriptar y no puedes retornar el valor anterior por ningun medio...

pero si utilizas RSACryptoServiceProvider si puedes desencriptar lo encriptado ....

bytEncrypted = sec.Encrypt(bytString, False)

espero hayas entendido, porque no puedes desencriptarlo .....
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:Desencriptar texto

Publicado por ivan (1 intervención) el 13/08/2007 21:04:11
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="image" src="https://www.paypal.com/en_US/i/btn/x-click-but03.gif"
border="0" name="submit" alt="Buy">
<input type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UGF5UGFsIEluYy4xEzAR
BgNVBAsUCmxpdmVfY2VydHMxETAPBgNVBAMUCGxpdmVfYXBpMRwwGgYJKoZIhvcNAQkBFg1yZUBwYX
lwYWwuY29tAgEAMAkGBSsOAwIaBQCgXTAYBgkqhkiG9w0BCQMxCwYJKoZIhvcNAQcBMBwGCSqGSIb3
DQEJBTEPFw0wNDEyMjgxNzU3MTVaMCMGCSqGSIb3DQEJBDEWBBQnjhigP+EwdfTLyWpgRzpPEmRSRz
ANBgkqhkiG9w0BAQEFAASBgB4SgJxKDANsuaSu8MgAdRlOTcH1Q376VMe7YMi9jwtAA/34+GCSnCb1
xOoQFWrlC15mOfsUxatnrpXv4uwNth+OsZNnjmkpNFslS7U2/wjAScG6Gos0p0TZiVsuwSUTT59D1l
KDmZfTv3fn/pSZaG5qgC7sbezsMmo/J2OVo9NV-----END PKCS7-----">
</form>
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:Desencriptar texto

Publicado por carlos contreras cruz (1 intervención) el 26/09/2007 04:22:07
accept=1&em=e3833b167365b268&secret=DD8E7E97BF5CFBAE&ed=B7QMc1gROROtd4pM6q/8ubZBtR5rPR%2bjS%2b7ERun7crhxZIjngOYQ1tDlvF296pZjVWIsjRA%3d&bk=1190775335&lc=3082
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar