- 2025-07-28 1.0.11 Se modifica funcion SHA256 para que no use métodos obsoletos y para que admita un encoding diferente a unicode

This commit is contained in:
2025-07-29 09:18:57 +02:00
parent 5422b6b686
commit b12e07c8f9
2 changed files with 23 additions and 19 deletions

View File

@@ -101,26 +101,29 @@ Public Class crypt
End Function
Public Shared Function SHA256(ByVal Datos() As Byte) As String
Dim sha256Obj As New Security.Cryptography.SHA256CryptoServiceProvider
Dim bytesToHash() As Byte = Datos
bytesToHash = sha256Obj.ComputeHash(bytesToHash)
Dim strResult As String = ""
For Each b As Byte In bytesToHash
strResult += b.ToString("x2")
Next
Return strResult.ToUpper
Using sha256Obj As Security.Cryptography.SHA256 = Security.Cryptography.SHA256.Create()
Dim bytesToHash() As Byte = sha256Obj.ComputeHash(Datos)
Dim strResult As String = ""
For Each b As Byte In bytesToHash
strResult += b.ToString("x2")
Next
Return strResult.ToUpper()
End Using
End Function
Public Shared Function SHA256(ByVal Cadena As String) As String
Dim sha256Obj As New Security.Cryptography.SHA256CryptoServiceProvider
Dim Datos() As Byte = System.Text.Encoding.Unicode.GetBytes(Cadena)
Dim bytesToHash() As Byte = Datos
bytesToHash = sha256Obj.ComputeHash(bytesToHash)
Dim strResult As String = ""
For Each b As Byte In bytesToHash
strResult += b.ToString("x2")
Next
Return strResult.ToUpper
Public Shared Function SHA256(ByVal Cadena As String, Optional ByVal encoding As System.Text.Encoding = Nothing) As String
Using sha256Obj As Security.Cryptography.SHA256 = Security.Cryptography.SHA256.Create()
If encoding Is Nothing Then
encoding = System.Text.Encoding.Unicode
End If
Dim Datos() As Byte = encoding.GetBytes(Cadena)
Dim bytesToHash() As Byte = sha256Obj.ComputeHash(Datos)
Dim strResult As String = ""
For Each b As Byte In bytesToHash
strResult += b.ToString("x2")
Next
Return strResult.ToUpper()
End Using
End Function
Public Shared Function ObtenerCadenaHashSHA256AportandoSal(ByVal cadenaQueQuieroHashear As String, ByVal sal As String)
Dim sb As Text.StringBuilder = New Text.StringBuilder()