change string back to byte
-
perviously I convert a byte array to string/text and store into database, like coding below:
cmd.Parameters("@LeadFormControls").Value = System.Text.Encoding.UTF8.GetString (bytLeadFormControls)
how do I convert back string/text back to a byte arrry when i retrieve it from database. Any idea?:confused: Angela -
perviously I convert a byte array to string/text and store into database, like coding below:
cmd.Parameters("@LeadFormControls").Value = System.Text.Encoding.UTF8.GetString (bytLeadFormControls)
how do I convert back string/text back to a byte arrry when i retrieve it from database. Any idea?:confused: AngelaTypically, you'd use the StringBuilder[^]class.
Dave Kreskowiak Microsoft MVP - Visual Basic
-
perviously I convert a byte array to string/text and store into database, like coding below:
cmd.Parameters("@LeadFormControls").Value = System.Text.Encoding.UTF8.GetString (bytLeadFormControls)
how do I convert back string/text back to a byte arrry when i retrieve it from database. Any idea?:confused: AngelaHere is a class I found and modified to encrypt/decrypt. Hope it helps you.
Imports System.IO
Imports System.Text
Imports System.Security.CryptographyPublic Class Encryption64
Private key() As Byte = {}
Private IV() As Byte = {&H11, &H22, &H33, &H44, &H55, &H66, &H77, &H88}Public Function Decrypt(ByVal strToDecrypt As String, \_ ByVal strEncryptionKey As String) As String '\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* ' This function will: ' - Accept a string and encryption key ' - Decrypt and return the string ' ' NOTE: If strToDecrypt is from a query string, ' the Request.QueryString will have replaced ' any '+' characters with a space. '\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* Dim inputByteArray(strToDecrypt.Length) As Byte Dim des As New DESCryptoServiceProvider() Dim ms As New MemoryStream() Try 'Set key key = System.Text.Encoding.UTF8.GetBytes(Left(strEncryptionKey, 8)) 'Convert input string into byte array inputByteArray = Convert.FromBase64String(strToDecrypt) 'Perform the decryption with memory stream object Dim cs As New CryptoStream(ms, des.CreateDecryptor(key, IV), CryptoStreamMode.Write) cs.Write(inputByteArray, 0, inputByteArray.Length) cs.FlushFinalBlock() 'Convert and return decrypted byte array in memory stream into string Dim encoding As System.Text.Encoding = System.Text.Encoding.UTF8 Return encoding.GetString(ms.ToArray()) Catch e As Exception Return e.Message End Try End Function Public Function Encrypt(ByVal strToEncrypt As String, \_ ByVal strEncryptionKey As String) As String '\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* ' This function will: ' - Accept a string and encryption key ' - Encrypt and return the string '\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* Dim des As New DESCryptoServiceProvider() Dim ms As New MemoryStream() Try 'Set ke
-
perviously I convert a byte array to string/text and store into database, like coding below:
cmd.Parameters("@LeadFormControls").Value = System.Text.Encoding.UTF8.GetString (bytLeadFormControls)
how do I convert back string/text back to a byte arrry when i retrieve it from database. Any idea?:confused: Angela