- 2025-07-22 1.0.6 Nuevas funciones de encriptartexto y desencriptartexto
This commit is contained in:
58
crypt.vb
58
crypt.vb
@@ -1,5 +1,6 @@
|
|||||||
Imports System.IO
|
Imports System.IO
|
||||||
Imports System.Security.Cryptography
|
Imports System.Security.Cryptography
|
||||||
|
Imports System.Text
|
||||||
|
|
||||||
Public Class crypt
|
Public Class crypt
|
||||||
Public Shared Function FEncS$(ByVal X$, ByVal Jco0$, ByVal Jcd0$, ByVal Xs0 As Long)
|
Public Shared Function FEncS$(ByVal X$, ByVal Jco0$, ByVal Jcd0$, ByVal Xs0 As Long)
|
||||||
@@ -502,4 +503,61 @@ Public Class crypt
|
|||||||
Return res
|
Return res
|
||||||
|
|
||||||
End Function
|
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
|
End Class
|
||||||
@@ -16,11 +16,12 @@
|
|||||||
<TargetFramework>net8.0</TargetFramework>
|
<TargetFramework>net8.0</TargetFramework>
|
||||||
<PackageId>tsUtilidades</PackageId>
|
<PackageId>tsUtilidades</PackageId>
|
||||||
<PackageTags>net8.0, libreria</PackageTags>
|
<PackageTags>net8.0, libreria</PackageTags>
|
||||||
<Version>1.0.5</Version>
|
<Version>1.0.6</Version>
|
||||||
<Authors>Manuel</Authors>
|
<Authors>Manuel</Authors>
|
||||||
<Company>Tecnosis S.A</Company>
|
<Company>Tecnosis S.A</Company>
|
||||||
<Description>Utilidades varias Entity Framework compatibles con EF Core 8.</Description>
|
<Description>Utilidades varias Entity Framework compatibles con EF Core 8.</Description>
|
||||||
<PackageReleaseNotes>
|
<PackageReleaseNotes>
|
||||||
|
- 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
|
- Se traslada a tecnosis.git no hay cambios respecto a la 1.0.1
|
||||||
</PackageReleaseNotes>
|
</PackageReleaseNotes>
|
||||||
<PackageReadmeFile>README.md</PackageReadmeFile>
|
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||||
|
|||||||
Reference in New Issue
Block a user