G
Guest
DISCLAIMER: I know what the words mean (i.e. by definition), but I in know
way pretend to understand the specifics of either, therefore I may need a
basic primer before I can accomplish this task, but the instructions I
received do not seem correct.
I need to covert a hex string to base64 and was told to
1. convert from the HEX string to a byte array
2. convert the byte array to Base64 encoding
3. the two encodings would produce the same byte array
I search MSDN and this forum and came up with the following (the database
field is NVARCHAR, therefore I used the UnicodeEncoding object):
Did I not understand the instructions or is this impossible?
static void Main(){
string sHex = "38-B8-B7-22-2A-E6-C6-D9-42-C7-63-40-69-DB-E0-66",
sHexBytes="", sBase64Bytes="", sBse64="";
string sLine =
"\n**********************************************************\n";
byte[] aHexByte, a64Byte;
UnicodeEncoding uencode = new UnicodeEncoding();
//ASCIIEncoding ascii = new ASCIIEncoding();
//get byte array from V3 hex encoded string
//aHexByte = uencode.GetBytes(sHex.Replace("-",""));
aHexByte = uencode.GetBytes(sHex);
//convert this to Base64 encoding
sBse64 = Convert.ToBase64String(aHexByte);
//get byte array from the Base64 encode string
a64Byte = uencode.GetBytes(sBse64);
//display on screen
foreach(byte b in aHexByte){
sHexBytes += b.ToString() + "/";
}
foreach(byte b in a64Byte){
sBase64Bytes += b.ToString() + "/";
}
Console.WriteLine("Hex encoded password:\n" + sHex + sLine);
Console.WriteLine("Bytes from Hex encode password:\n" + sHexBytes + sLine);
Console.WriteLine("Base64 encoding of Bytes from Hex string:\n" + sBse64 +
sLine);
Console.WriteLine("Bytes from Base64 encoded strng:\n" + sBase64Bytes +
sLine);
Console.ReadLine();
}
way pretend to understand the specifics of either, therefore I may need a
basic primer before I can accomplish this task, but the instructions I
received do not seem correct.
I need to covert a hex string to base64 and was told to
1. convert from the HEX string to a byte array
2. convert the byte array to Base64 encoding
3. the two encodings would produce the same byte array
I search MSDN and this forum and came up with the following (the database
field is NVARCHAR, therefore I used the UnicodeEncoding object):
Did I not understand the instructions or is this impossible?
static void Main(){
string sHex = "38-B8-B7-22-2A-E6-C6-D9-42-C7-63-40-69-DB-E0-66",
sHexBytes="", sBase64Bytes="", sBse64="";
string sLine =
"\n**********************************************************\n";
byte[] aHexByte, a64Byte;
UnicodeEncoding uencode = new UnicodeEncoding();
//ASCIIEncoding ascii = new ASCIIEncoding();
//get byte array from V3 hex encoded string
//aHexByte = uencode.GetBytes(sHex.Replace("-",""));
aHexByte = uencode.GetBytes(sHex);
//convert this to Base64 encoding
sBse64 = Convert.ToBase64String(aHexByte);
//get byte array from the Base64 encode string
a64Byte = uencode.GetBytes(sBse64);
//display on screen
foreach(byte b in aHexByte){
sHexBytes += b.ToString() + "/";
}
foreach(byte b in a64Byte){
sBase64Bytes += b.ToString() + "/";
}
Console.WriteLine("Hex encoded password:\n" + sHex + sLine);
Console.WriteLine("Bytes from Hex encode password:\n" + sHexBytes + sLine);
Console.WriteLine("Base64 encoding of Bytes from Hex string:\n" + sBse64 +
sLine);
Console.WriteLine("Bytes from Base64 encoded strng:\n" + sBase64Bytes +
sLine);
Console.ReadLine();
}