Covert String to Byte[]
Covert String to Byte[]
(OP)
Dear All,
Please help this is driving me mad!
Thanks in advance :)
I get the following error:
[error]
Input string was not in a correct format.
[/error]
I have also tried the following:
Please help, thanks.
Please help this is driving me mad!
Thanks in advance :)
CODE --> c#
try { var emailAddr = "etpienaar@yahoo.com"; byte[] emailAddrByteArr = new byte[emailAddr.Length]; string[] emailAddStArr = new string[]{"e","t","p","i","e","n","a","a","r","@","y","a","h","o","o",".","c","o","m"}; //string[] emailAddStArr = new string[emailAddr.Length]; char[] emailCharArr = emailAddr.ToCharArray(); for (int i = 0; i < emailAddr.Length; i++) { //Console.WriteLine(emailCharArr[i]); Console.WriteLine(emailAddStArr[i]); emailAddrByteArr[i] = byte.Parse(emailAddStArr[i]); }
[error]
Input string was not in a correct format.
[/error]
I have also tried the following:
CODE --> c#
//emailAddrByteArr = Array.ConvertAll(emailAddStArr, s => Convert.ToByte(s, 8)); //emailAddrByteArr = Encoding.ASCII.GetBytes(emailAddr); //Encoding srcEncoding = Encoding.Unicode; //Encoding dstEncoding = Encoding.UTF8; //emailAddrByteArr = Encoding.Convert(srcEncoding,dstEncoding,emailAddrByteArr);
Please help, thanks.
Thank you,
Kind regards
Triacona
RE: Covert String to Byte[]
I think you are overcomplicating things.
A string already _is_ a character array. No need to define a string array first and then trying to convert to char array.
All you need to do is something along the line of this:
CODE
Best,
MakeItSo
"Knowledge is power. Information is liberating. Education is the premise of progress, in every society, in every family." (Kofi Annan)
Oppose SOPA, PIPA, ACTA; measures to curb freedom of information under whatever name whatsoever.
RE: Covert String to Byte[]
I will give that a go...
Thank you,
Kind regards
Triacona
RE: Covert String to Byte[]
I have tried that and I get the following error :
Basically here is all the code:
It is to encrypt an object
CODE --> c#
Thanks for your help
Thank you,
Kind regards
Triacona
RE: Covert String to Byte[]
etpienaa
and it gives me the following error:
Thank you,
Kind regards
Triacona
RE: Covert String to Byte[]
The decryption method expects a Base64 string of encrypted data. Base64 strings are always the length of a multiple of 4, with "=" used as padding for the end of the string, if required. This is what your two error messages say: a) not a multiple of 4, b) not padded with "=".
Next error would be "not a valid Base64 string", probably.
For instance, this is how I encrypt a string (wrote this almost four years ago, so could probably be optimized...
CODE
CODE
In the same fashion, I decrypt encrypted strings like this:
CODE
Again, calling the second Decrypt() directly:
CODE
You'll need using System.Security.Cryptography;
Encryption is not trivial but totally worth - if done properly. :)
Best,
MakeItSo
"Knowledge is power. Information is liberating. Education is the premise of progress, in every society, in every family." (Kofi Annan)
Oppose SOPA, PIPA, ACTA; measures to curb freedom of information under whatever name whatsoever.
RE: Covert String to Byte[]
The blasted text book I am trying to teach myself out of is really bad, with a load of mistakes ( MS Cert 20483, 2013 version ).
I will try this out with the information you have provided.
Thanks again.
Thank you,
Kind regards
Triacona
RE: Covert String to Byte[]
The accepted answer from here (currently 511 votes) is a very good example, also with a link to a sample solution etc.:
https://stackoverflow.com/questions/10168240/encry...
That being said, my above code snippet should already get you started.
"Knowledge is power. Information is liberating. Education is the premise of progress, in every society, in every family." (Kofi Annan)
Oppose SOPA, PIPA, ACTA; measures to curb freedom of information under whatever name whatsoever.
RE: Covert String to Byte[]
"Knowledge is power. Information is liberating. Education is the premise of progress, in every society, in every family." (Kofi Annan)
Oppose SOPA, PIPA, ACTA; measures to curb freedom of information under whatever name whatsoever.
RE: Covert String to Byte[]
Not yet, I have been really busy at work.
I will give it a go over the next few days
Thanks
Thank you,
Kind regards
Triacona
RE: Covert String to Byte[]
See below:
CODE --> c#
Thanks for all your help
Thank you,
Kind regards
Triacona