.NET 4.5 verses .NET Micro

As usual I have a ‘off the wall’ question.
I have been fighting a problem with encryption to be used between a FEZ.Raptor and a Windows form.

I finally found the problem but I have no answer for it at the moment.

Root cause is that in some encrypted strings there may be a ‘\0’.
.NET strings seem to allow the ‘\0’. However .NET Micro does not. (At least in my code)?

Example:



public string EncryptString(string Data, string Key)
{
     uint[] formattedKey = FormatKey(Key);

     if (Data.Length % 2 != 0) // Make sure array has even length.
     {
           if(Data.Length %2 != 0)
           {
	Data += '\0'; //<This does not work. Data remains the same
           }
    }
	......
	......
}
//

	.Net Micro
	string a = string.Empty;
	string b = string.Empty;
	string c = string.Empty;
	string d = string.Empty;
	string e = string.Empty;
	string f = string.Empty;
	string g = string.Empty;
	string h = string.Empty;
	string i = string.Empty;
	string j = string.Empty;
	string k = string.Empty;

	//character literals to strings
	a += '\'';  //Single quote
	b += '\"';  //Double quote
	c += '\\';  //Backslash
	d += '\0';  //Null
	e += '\a';  //Alert
	f += '\b';  //Backspace
	g += '\f';  //Form feed
	h += '\n';  //New line
	i += '\r';  //Carriage return
	j += '\t';  //Horizontal tab
	k += '\v';  //Vertical tab

	//Resulting strings
	a	"'"	string
	b	"\""	string
	c	"\\"	string
	d	""	string <<<<
	e	"\a"	string
	f	"\b"	string
	g	"\f"	string
	h	"\n"	string
	i	"\r"	string
	j	"\t"	string
	k	"\v"	string
    
	.NET 4.5
	//Resulting strings
	a	"'"	string
	b	"\""	string
	c	"\\"	string
	d	"\0"	string <<<<
	e	"\a"	string
	f	"\b"	string
	g	"\f"	string
	h	"\n"	string
	i	"\r"	string
	j	"\t"	string
	k	"\v"	string


Anyone know a way around this?

Thanks!

Does Stringbuilder work? Or can you do it as a byte array?

@ willgeorge - does “\0” help?

@ hagster -

I need to use a string. I am going to try the ‘\0’ later.
However I am going to try using Microsoft.SPOT.Cryptography; that works on the Raptor.
I need time to try my luck using the source code I found on my Windows Form.

Have a great day…

EDIT:
’\0’ later. Cannot, I must use a char ‘\0’ - ‘\0’ fails as I thought it would

Be careful. I tried AES, but had to reimplement it myself. On my G400 boards, it was randomly spewing OutOfMemory eceptions (there was plenty of free memory).

@ Simon from Vilnius -

Thanks for the info.
As my use is only a experiment for now I will keep this in mind and see what happens.

I have a friend close by and we can access our routers (ad hoc) just to see if it works.

Off topic, I know, but remember, “OutOfMemoryException” doesn’t mean the memory is all full, it merely means “could not allocate the memory you requested” (for whatever reason). Only one of those reasons is “not enough memory”. There’s others, as well.