Public hash As String = "@H45H@"
Public Function encriptar(ByVal str As String) As String
Dim data As Byte() = UTF8Encoding.UTF8.GetBytes(str)
Dim transform As ICryptoTransform
Dim results As Byte()
Dim keys As Byte()
Using md5 As MD5CryptoServiceProvider = New MD5CryptoServiceProvider
keys = md5.ComputeHash(UTF8Encoding.UTF8.GetBytes(hash))
Using tripDes As TripleDESCryptoServiceProvider = New TripleDESCryptoServiceProvider
tripDes.Key = keys
tripDes.Mode = CipherMode.ECB
tripDes.Padding = PaddingMode.PKCS7
transform = tripDes.CreateEncryptor
results = transform.TransformFinalBlock(data, 0, data.Length)
Return Convert.ToBase64String(results, 0, results.Length)
End Using
End Using
End Function
' Using tripDes As TripleDESCryptoServiceProvider = New TripleDESCryptoServiceProvider With {.Key = keys, .Mode = CipherMode.ECB, .Padding = PaddingMode.PKCS7}
Public Function desencriptar(ByVal str As String) As String
Dim data As Byte() = Convert.FromBase64String(str)
Dim transform As ICryptoTransform
Dim results As Byte()
Dim keys As Byte()
Using md5 As MD5CryptoServiceProvider = New MD5CryptoServiceProvider
keys = md5.ComputeHash(UTF8Encoding.UTF8.GetBytes(hash))
Using tripDes As TripleDESCryptoServiceProvider = New TripleDESCryptoServiceProvider
tripDes.Key = keys
tripDes.Mode = CipherMode.ECB
tripDes.Padding = PaddingMode.PKCS7
transform = tripDes.CreateDecryptor
results = transform.TransformFinalBlock(data, 0, data.Length)
Return UTF8Encoding.UTF8.GetString(results)
End Using
End Using
End Function
fuente
No hay comentarios.:
Publicar un comentario