diff --git a/crypt.vb b/crypt.vb
index f738ef4..9567bdb 100644
--- a/crypt.vb
+++ b/crypt.vb
@@ -1,5 +1,6 @@
Imports System.IO
Imports System.Security.Cryptography
+Imports System.Text
Public Class crypt
Public Shared Function FEncS$(ByVal X$, ByVal Jco0$, ByVal Jcd0$, ByVal Xs0 As Long)
@@ -502,4 +503,61 @@ Public Class crypt
Return res
End Function
+
+
+
+
+ Private Shared Function GetKey(password As String) As Byte()
+ Using sha256 As SHA256 = SHA256.Create()
+ Return sha256.ComputeHash(Encoding.UTF8.GetBytes(password))
+ End Using
+ End Function
+
+
+ Public Shared Function EncriptarTexto(Texto As String, password As String) As String
+ Dim key As Byte() = GetKey(password)
+ Dim aes As Aes = Aes.Create()
+ aes.Key = key
+ aes.Mode = CipherMode.CBC
+ aes.Padding = PaddingMode.PKCS7
+ aes.GenerateIV()
+
+ Dim iv As Byte() = aes.IV
+ Dim encryptor = aes.CreateEncryptor()
+
+ Dim plainBytes = Encoding.UTF8.GetBytes(Texto)
+ Dim ms As New MemoryStream()
+ ms.Write(iv, 0, iv.Length) ' Guardamos el IV al principio
+ Using cs As New CryptoStream(ms, encryptor, CryptoStreamMode.Write)
+ cs.Write(plainBytes, 0, plainBytes.Length)
+ cs.FlushFinalBlock()
+ End Using
+
+ Return Convert.ToBase64String(ms.ToArray())
+ End Function
+
+ Public Shared Function DesencriptarTexto(Texto As String, password As String) As String
+ Dim fullCipher = Convert.FromBase64String(Texto)
+ Dim key As Byte() = GetKey(password)
+
+ Dim aes As Aes = Aes.Create()
+
+ aes.Key = key
+ aes.Mode = CipherMode.CBC
+ aes.Padding = PaddingMode.PKCS7
+
+ Dim iv(15) As Byte
+ Array.Copy(fullCipher, iv, iv.Length)
+ aes.IV = iv
+
+ Dim decryptor = aes.CreateDecryptor()
+ Dim ms As New MemoryStream()
+ Using cs As New CryptoStream(ms, decryptor, CryptoStreamMode.Write)
+ cs.Write(fullCipher, iv.Length, fullCipher.Length - iv.Length)
+ cs.FlushFinalBlock()
+ End Using
+
+ Return Encoding.UTF8.GetString(ms.ToArray())
+ End Function
+
End Class
\ No newline at end of file
diff --git a/tsUtilidades.vbproj b/tsUtilidades.vbproj
index 452cc93..505e2e0 100644
--- a/tsUtilidades.vbproj
+++ b/tsUtilidades.vbproj
@@ -16,11 +16,12 @@
net8.0
tsUtilidades
net8.0, libreria
- 1.0.5
+ 1.0.6
Manuel
Tecnosis S.A
Utilidades varias Entity Framework compatibles con EF Core 8.
+ - 2025-07-22 1.0.6 Nuevas funciones de encriptartexto y desencriptartexto
- Se traslada a tecnosis.git no hay cambios respecto a la 1.0.1
README.md