I am using Triple DES algorithm for encryption.While doing that i need to pass in a hex decimal(32 characters) key.When i convert that to byte array it's gets stored in 32 bytes.But the input key to the algorithm should of 16 bytes only.So my question is how to store 32 hex decimal digits in 16 byte array?
Asked
Active
Viewed 1,317 times
1 Answers
1
What you are after is probably similar to this extension method
public static byte[] HexToByteArray(this string hex)
{
hex = hex.Replace(" ", "").Replace("-", "");
var numberChars = hex.Length;
var bytes = new byte[numberChars / 2];
for (var i = 0; i < numberChars; i += 2)
bytes[i / 2] = Convert.ToByte(hex.Substring(i, 2), 16);
return bytes;
}
You have a string that looks something like "A123FF25", and you want to treat each 2-char block in that string as a hexadecimal number, and get a byte array out of that that is half the length of the original...

Jakob Olsen
- 793
- 8
- 13