Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 18-02-2009
Member
 
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?
Reply With Quote
  #2  
Old 18-02-2009
Member
 
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.
Reply With Quote
  #3  
Old 18-02-2009
Member
 
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 ...
Reply With Quote
  #4  
Old 18-02-2009
XSI XSI is offline
Member
 
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) ?
Reply With Quote
  #5  
Old 18-02-2009
Member
 
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
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


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


All times are GMT +5.5. The time now is 07:25 PM.