Results 1 to 5 of 5

Thread: Convert a string to bytes

  1. #1
    Join Date
    Nov 2008
    Posts
    1,221

    Convert a string to bytes

    Here is my code that I have a problem:

    Code:
    InputText = "sklfjlkjd"; 
    byte [] EncryptedData = Convert.FromBase64String (InputText) // Error on line: Invalid length for a Base-64 char array. 
    There is no white in my string so I do not understand too well the error.

    Any idea?

  2. #2
    Join Date
    May 2008
    Posts
    945

    Re: Convert a string to bytes

    Is it toBase64 that you want to do?

    Probably you made a mistake in writing the code.

  3. #3
    Join Date
    May 2008
    Posts
    685

    Re: Convert a string to bytes

    Your string is not a multiple of 4 (in length). If the string contains base64, it should be padded with "=" at the end if it is not multiple of 4

    I also wonder if this is not the opposite that you want to do ...

  4. #4
    Join Date
    May 2008
    Posts
    271

    Re: Convert a string to bytes

    Why don't you use something like System.Text.ASCIIEncoding.ASCII.GetBytes(s) ?

  5. #5
    Join Date
    May 2008
    Posts
    3,971

    Re: Convert a string to bytes

    Convert.FromBase64String Method

    Converts the specified String, which encodes binary data as base 64 digits, to an equivalent 8-bit unsigned integer array.

    For more information, look here: http://msdn.microsoft.com/en-us/libr...e64string.aspx

Similar Threads

  1. SanDisk flash drive “0 bytes used and 0 bytes free”
    By Coloma in forum Hardware Peripherals
    Replies: 5
    Last Post: 03-12-2012, 10:56 AM
  2. Convert XML string into DOM
    By GreatThinker in forum Software Development
    Replies: 6
    Last Post: 22-07-2010, 09:48 AM
  3. Convert IP address to array of bytes
    By Gunner 1 in forum Software Development
    Replies: 5
    Last Post: 03-03-2010, 11:54 AM
  4. How to convert bytes to bits
    By CitricAcid in forum Software Development
    Replies: 3
    Last Post: 14-08-2009, 05:51 PM
  5. How to convert Bytes to Megabytes
    By Girish-S in forum India BroadBand
    Replies: 2
    Last Post: 15-06-2009, 02:47 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,032,831.12244 seconds with 17 queries