Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. change string back to byte

change string back to byte

Scheduled Pinned Locked Moved Visual Basic
questiondatabasedata-structures
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    angelagke
    wrote on last edited by
    #1

    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

    D K E 3 Replies Last reply
    0
    • A angelagke

      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

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      Typically, you'd use the StringBuilder[^]class.

      Dave Kreskowiak Microsoft MVP - Visual Basic

      1 Reply Last reply
      0
      • A angelagke

        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

        K Offline
        K Offline
        Kschuler
        wrote on last edited by
        #3

        Here is a class I found and modified to encrypt/decrypt. Hope it helps you.

        Imports System.IO
        Imports System.Text
        Imports System.Security.Cryptography

        Public 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
        
        1 Reply Last reply
        0
        • A angelagke

          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

          E Offline
          E Offline
          emiaj
          wrote on last edited by
          #4

          byte[] info = System.Text.Encoding.UTF8.GetBytes("hello world");

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups