Torna al Thread

'Come crittare una stringa di connessione: Module Module1 Const KEY As String = "GxDNsofLPXc=" 'BASE64 della chiave in byte Const SALT As String = "it04UBmAabw=" 'BASE64 del salto in byte Sub Main() Dim des As New Security.Cryptography.DESCryptoServiceProvider 'DES è un algoritmo sincrono di crittazione che offre una protezione media 'cambiando algoritmo con uno migliore cambia la dimensione delle chiavi des.IV = Convert.FromBase64String(SALT) des.Key = Convert.FromBase64String(KEY) Dim crytoString As String 'qui ci va la stringa di connessione cifrata in BASE64 Using m As New IO.MemoryStream Using CryptoStreamWriter As New Security.Cryptography.CryptoStream(m, des.CreateEncryptor, Security.Cryptography.CryptoStreamMode.Write) Using w As New IO.StreamWriter(CryptoStreamWriter) w.WriteLine("Data source=DBSYS; Initial catalog=TEST; User ID=user; password=pwwww;") End Using End Using crytoString = Convert.ToBase64String(m.ToArray) End Using 'cryptoString=IKEpuIEOjO925z8gSEjPtG/GPRN/uCKxXXXhLQfBnONo8BLWHnbs2pYt4NuGHPKjAP9aU+/YwCW7N8h7OK5ncHD773tvbsNhLUM/UTBK4WE= 'decrittazione Dim connString As String Using m As New IO.MemoryStream(Convert.FromBase64String(crytoString)) Using CryptoStreamReader As New Security.Cryptography.CryptoStream(m, des.CreateDecryptor, Security.Cryptography.CryptoStreamMode.Read) Using r As New IO.StreamReader(CryptoStreamReader) connString = r.ReadLine End Using End Using End Using 'connString=Data source=DBSYS; Initial catalog=TEST; User ID=user; password=pwwww; End Sub End Module
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5