Dim rng As New RNGCryptoServiceProvider() Dim buff As Byte() = New Byte(size) rng.GetBytes(buff) Return Convert.ToBase64String(buff)
' Create a new instance of the hash crypto service provider. Dim hashAlg As HashAlgorithm = New SHA256CryptoServiceProvider() ' Convert the data to hash to an array of Bytes. Dim bytValue As Byte() = System.Text.Encoding.UTF8.GetBytes(stringDataToHash) ' Compute the Hash. This returns an array of Bytes. Dim bytHashValue As Byte() = hashAlg.ComputeHash(bytValue) ' Optionally, represent the hash value as a base64-encoded string. Dim bytHashValue64 As String = Convert.ToBase64String(bytHashValue) Return bytHashValue64
Public Shared Sub SaltAndHashPassword(ByVal password As String, ByRef saltvalue() As Byte, ByRef passwordhashed() As Byte) Dim rdb As New Rfc2898DeriveBytes(password, SALT_SIZE, ITERATIONS) saltvalue = rdb.Salt passwordhashed = rdb.GetBytes(HASH_SIZE) End Sub
Private Function IV_192() Dim strKey As String = ReturnKey() Dim strIV1 As String = Left(strKey, 10) Dim strIV2 As String = Right(strKey, 25) Dim strIV3 As String = strIV1 & strIV2 Dim IV_192() As Byte = Encoding.ASCII.GetBytes(strIV3.ToCharArray) Return IV_192 End Function
Private Function KEY_192() Dim strKey As String = ReturnKey() Dim strK1 As String = Left(strKey, 30) Dim strK2 As String = Right(strKey, 5) Dim strK3 As String = strK1 & strK2 vKey = EncryptVariable(strK3) Dim KEY_192() As Byte = Encoding.ASCII.GetBytes(strKey.ToCharArray) Return KEY_192 End Function
Rfc2898DeriveBytes(Byte(), Byte(), Int32) (Initializes a new instance of the Rfc2898DeriveBytes class using a password, a salt, and number of iterations to derive the key.) Rfc2898DeriveBytes.Salt (Gets or sets the key salt value for the operation.) Rfc2898DeriveBytes.GetByte(Size) (Returns the pseudo-random key for this object.)
Private Function Encrypt(ByVal Value As String) As String Dim cspDES As New TripleDESCryptoServiceProvider() Dim ct As ICryptoTransform Dim ms As MemoryStream = New MemoryStream() Dim cs As CryptoStream Dim byt() As Byte ' convert a binary string representation of a key/iv into a byte array cspDES.Key = Convert.FromBase64String(KEY_192) cspDES.IV = Convert.FromBase64String(IV_192) ' convert the input string into a byte array byt = Encoding.UTF8.GetBytes(Value) ' create an object to perform the actual encryption ct = cspDES.CreateEncryptor() ' the encryption cs = New CryptoStream(ms, ct, CryptoStreamMode.Write) cs.Write(byt, 0, byt.Length) ' ensure all the data has been written into the MemoryStream object cs.FlushFinalBlock() cs.Close() ' use ToArray() method to get the array of bytes out of the memory stream ' convert the memory stream from an array of bytes back into a string Return Convert.ToBase64String(ms.ToArray()) End Function
<connectionStrings> <add name="Northwind" connectionString="initial catalog=Northwind; data source=localhost; Integrated security= SSPI"; providername = "System.Data.SqlClient"> </add> </connectionStrings>
aspnet_regiis -pe "connectionStrings" -app "/SampleApplication"
aspnet_regiis -pd "connectionStrings" -app "/SampleApplication"