-1

I have string and want to convert it into hexadecimal in C#.net.

This is my Eset Nod32 password:

"12968"

The program saves this password into a binary registry key as:

"50 d6 e6 e9 e4 f0 cd f2 63 64"

How can I do this in C#?

CodeCaster
  • 147,647
  • 23
  • 218
  • 272
Mr.Milad
  • 57
  • 2
  • 12
  • 1
    What is the rule to map `12968` to `50 d6 e6 e9 e4 f0 cd f2 63 64`. I don't see any relation. – L.B Jan 25 '14 at 11:49
  • You have two questions, both of which have been answered already. Please use the search. See [Converting string value to hex decimal](http://stackoverflow.com/questions/8739577/converting-string-value-to-hex-decimal) and [How to write Binary Data “as is” to Registry](http://stackoverflow.com/questions/5087240/how-to-write-binary-data-as-is-to-registry-ie-i-have-visible-binary-data-as). – CodeCaster Jan 25 '14 at 11:54
  • It's obviously not such a simple relation. There are 80 bits in hex, the input is far smaller. It's probably some kind of hash or something to prevent you from doing precisely the thing you're trying to do. – harold Jan 25 '14 at 12:14
  • I edited your question based on your [comment](http://stackoverflow.com/questions/21349779/how-can-convert-string-into-hexadecimal-in-c-net#comment32190268_21350137). Sinds Nod32 does not come with source code, we do not know how it encrypts or hashes your password. This may very well be impossible to reproduce, unless you have a lot of time. – CodeCaster Jan 25 '14 at 12:18

2 Answers2

0

If you want to get the HEX of each number, for example Hex of 1, Hex of 2 , etc. you can do as below:

string input = "12968";
char[] values = input.ToCharArray();
foreach (char letter in values)
{
    // Get the integral value of the character. 
    int value = Convert.ToInt32(letter);
    // Convert the decimal value to a hexadecimal value in string form. 
    string hexOutput = String.Format("{0:X}", value);
    Console.WriteLine("Hexadecimal value of {0} is {1}", letter, hexOutput);
}

or if you want get the complete string as a float number for example this is the way :

string hexString = "12968";
uint num = uint.Parse(hexString, System.Globalization.NumberStyles.AllowHexSpecifier);

byte[] floatVals = BitConverter.GetBytes(num);
float f = BitConverter.ToSingle(floatVals, 0);
Console.WriteLine("float convert = {0}", f);
Nima Soroush
  • 12,242
  • 4
  • 52
  • 53
  • thanks dude . when i use your code . Output is "31 32 39 36 38" for "12968" but . i want convert to this Style "50 d6 e6 e9 e4 f0 cd f2 63 64" – Mr.Milad Jan 25 '14 at 11:36
  • It is not possible to get this value( "50 d6 e6 e9 e4 f0 cd f2 63 64" ) from your input just by converting to hex. with high probability your NOD32 doing some hashing or encryption on your password – Nima Soroush Jan 25 '14 at 19:29
0

There can be used following to write binary value to registry

static byte[] GetBytes(string str)
{
    byte[] bytes = new byte[str.Length * sizeof(char)];
    System.Buffer.BlockCopy(str.ToCharArray(), 0, bytes, 0, bytes.Length);
    return bytes;
}

RegistryKey rk = Registry.CurrentUser.CreateSubKey("RegistryValueKindExample");
rk.SetValue("BinaryValue", GetBytes("12968"), RegistryValueKind.Binary);

RegistryKey.SetValue Method

mybrave
  • 1,662
  • 3
  • 20
  • 37
  • thanks bro . but not this style : "50 d6 e6 e9 e4 f0 cd f2 63 64" yet :( – Mr.Milad Jan 25 '14 at 12:05
  • this is nod32 mapping . my EsetNod32 password is : 12968 . i navigate to Regedit and see "50 d6 e6 e9 e4 f0 cd f2 63 64" value for password . now i want set my New Password . but i have to recreate Value like this. – Mr.Milad Jan 25 '14 at 12:07