tags:

views:

38

answers:

3

Part 1) I have a bitmap/jpeg image. I need to convert this image into an ASCII string (because I need to hash it) How is this conversion to ASCII done?

Part 2) Then, I need to send this ASCII string from client to server using HTTP Post.

From what I understand, I can only send data as a byte array using HTTP Post. How can I send an ASCII string instead of byte[]?

Code in C# would be much appreciated!!

+1  A: 

You can convert any binary data to ASCII using base 64 encoding or mime encoding. I expect there are functions to do this in the .net framework. However, I think that's not exactly what you want to do. Here is why:

You can calculate a hash code of binary data, you do not need ASCII data in order to calculate a hash code. There are .net functions for calculating hashed that work with binary data. Also, you can do an http post of binary data, you don't have to use plain ASCII for a post.

Unoti
Thanks for the tip, I don't know much about Hashing. If the data is to be in ASCII string, how can a HTTP Post of ASCII string be done?
Robogal
A: 

One way to convert binary data such as an image into an ASCII string is to use base-64. An example of Base-64 encoding is at: http://arcanecode.com/2007/03/21/encoding-strings-to-base64-in-c/

Reinderien
A: 

You need to encode your image in Base64 so to form an ASCII string: http://en.wikipedia.org/wiki/Base64

You can do that in C# like this:

static public string EncodeTo64(string toEncode{
   byte[] toEncodeAsBytes = System.Text.ASCIIEncoding.ASCII.GetBytes(toEncode);
   string returnValue = System.Convert.ToBase64String(toEncodeAsBytes);
  return returnValue;
}
nivox
Anyway to hash you don't need an ASCII string! Look at http://www.vcskicks.com/compute-hash.php
nivox
Thanks! I found a link that explains how to convert an image from file to byte[] first. http://bytes.com/topic/c-sharp/answers/267613-ways-convert-image-base64-back
Robogal