textBox -to- Binary Registry
-
How can take the text from the textBox and save it as a Binary data in the registry? Many Thanks, Jassim Rahma
-
How can take the text from the textBox and save it as a Binary data in the registry? Many Thanks, Jassim Rahma
Hey Jassim, The Text is stored within textbox.Text property. Look in the C# articles for "QuickRegistry" and use that for storage. -Adrian
-
Hey Jassim, The Text is stored within textbox.Text property. Look in the C# articles for "QuickRegistry" and use that for storage. -Adrian
but this will just create a plain text and not binary one? how to convert it to binary? Jassim
-
but this will just create a plain text and not binary one? how to convert it to binary? Jassim
In order to store something as a REG_BINARY type using .Net, it needs to be passed as a byte array. Getting a byte array from a string is as simple as:
byte[] bytArray = System.Text.Encoding.Unicode.GetBytes(textBox.Text);
Then pass bytArray into a RegistryKey's SetValue() function:MyRegKey.SetValue("MyBinaryEntry", bytArray);
The CLR will automatically detect that the type is a byte array, and set the type accordingly. Retrieving that value will return a byte array also, not a string. Cheers -
In order to store something as a REG_BINARY type using .Net, it needs to be passed as a byte array. Getting a byte array from a string is as simple as:
byte[] bytArray = System.Text.Encoding.Unicode.GetBytes(textBox.Text);
Then pass bytArray into a RegistryKey's SetValue() function:MyRegKey.SetValue("MyBinaryEntry", bytArray);
The CLR will automatically detect that the type is a byte array, and set the type accordingly. Retrieving that value will return a byte array also, not a string. CheersBut this will not encode it and it will be easy for anyone to read it? how can have it encoded in the same code?
-
But this will not encode it and it will be easy for anyone to read it? how can have it encoded in the same code?
-
If you feel it's too easy for someone to read the binary data, there are any number of encryption algorithms out there. You can apply one before placing the data into the registry.
But will it be easy for someelse to decrypt it? I need to save a system pssword, what do you recommend? Jassim