In order to encrypt Data you should use the following sub:
Public Function EncodePassword(password As String) As String
Dim encodedPassword As String = password
Select Case pPasswordFormat
Case MembershipPasswordFormat.Clear
Case MembershipPasswordFormat.Encrypted
encodedPassword = _
Convert.ToBase64String(EncryptPassword(Encoding.Unicode.GetBytes(password)))
Case MembershipPasswordFormat.Hashed
Dim hash As HMACSHA384 = New HMACSHA384()
hash.Key = HexToByte(pMachineKey.ValidationKey)
encodedPassword = Convert.ToBase64String(hash.ComputeHash(Encoding.Unicode.GetBytes(password)))
Case Else
ErrorAnswer = "Password format not supported."
Return Nothing
End Select
Return encodedPassword.ToLower
End Function
In the web.config file you should add the line:
<machinekey validationkey="C50B3C89CB21F4F1422FF158A5B42D0E8DB8CB5CDA1742572A487D9401E3400267682B202B746511891C1BAF47F8D25C07F6C39A104696DB51F17C529AD3CABE">
decryptionKey="8A9BE8FD67AF6979E7D20198CFEA50DD3D3799C77AF2B72F"
validation="HMACSHA384" decryption="AES" /></machinekey>
And also if you want to make it more stronger.... please "Salt it" with the following sub:
Public Shared Function GetSaltKey() As String
Dim saltBytes() As Byte
Dim minSaltSize As Integer = 256
Dim maxSaltSize As Integer = 512
Dim random As Random
random = New Random()
Dim saltSize As Integer
saltSize = random.Next(minSaltSize, maxSaltSize)
saltBytes = New Byte(saltSize - 1) {}
Dim rng As RNGCryptoServiceProvider
rng = New RNGCryptoServiceProvider()
rng.GetNonZeroBytes(saltBytes)
Return Convert.ToBase64String(saltBytes)
End Function
Please... if you want to "salt" your data then do it outside of the Encryption Function because you want later to use the same "salt" to Encode the new coming input in order to compare with the written on your data base.
If you choose to "salt" the encoded data and keep the "salt" then you need to produce a record in your database with nvarchar(1024) and of course all the related "records declares" needs to be in the same Length.
Pay attention that this encode method is made with the SAH3 which is the most stronger method for encryption.
I don't know if I give you the answer you want it.... but in any case I've try it to!!!