Деревянное решение:
| Код | private string keyToHex(string keyPath) { byte[] key; using (FileStream fs = new FileStream(keyPath, FileMode.Open, FileAccess.Read)) { key = new byte[fs.Length]; fs.Read(key, 0, (int)fs.Length); } string st = ""; for (int x = 0; x < key.Length; x++) st = st + String.Format("{0:x02} ", key[x]); return(st.ToUpper()); }
|
Элегантное решение: никогда не подумал бы что метод BitConverter.ToString() "Converts the numeric value of each element of a specified array of bytes to its equivalent hexadecimal string representation"!!!
| Код | private string keyToHex(string keyPath) { byte[] key; using (FileStream fs = new FileStream(keyPath, FileMode.Open, FileAccess.Read)) { key = new byte[fs.Length]; fs.Read(key, 0, (int)fs.Length); } return (BitConverter.ToString(key).Replace('-',' ')); }
|
Вот. Как говорится - сам себе волшебник |