From b12e07c8f92fb056d926fa37e4a1bf3d4852b8c1 Mon Sep 17 00:00:00 2001 From: manuel Date: Tue, 29 Jul 2025 09:18:57 +0200 Subject: [PATCH] =?UTF-8?q?=20=20-=202025-07-28=201.0.11=20Se=20modifica?= =?UTF-8?q?=20funcion=20SHA256=20para=20que=20no=20use=20m=C3=A9todos=20ob?= =?UTF-8?q?soletos=20y=20para=20que=20admita=20un=20encoding=20diferente?= =?UTF-8?q?=20a=20unicode?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crypt.vb | 39 +++++++++++++++++++++------------------ tsUtilidades.vbproj | 3 ++- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/crypt.vb b/crypt.vb index a342549..ccef21b 100644 --- a/crypt.vb +++ b/crypt.vb @@ -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() diff --git a/tsUtilidades.vbproj b/tsUtilidades.vbproj index 86c160c..06bbf15 100644 --- a/tsUtilidades.vbproj +++ b/tsUtilidades.vbproj @@ -16,11 +16,12 @@ net8.0 tsUtilidades net8.0, libreria - 1.0.10 + 1.0.11 Manuel Tecnosis S.A Utilidades Varias + - 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 - 2025-07-28 1.0.10 Nueva función DescomponerCNsuscriptor - 2025-07-28 1.0.9 Correccion ObtenerValorDesdeNombre - 2025-07-28 1.0.8 Correccion ObtenerValorDesdeNombre