0

I want to iterate through the values of a specific path and read them. I tried this

Code updated

RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Internet Explorer\IntelliForms\Storage2", true);
        var names = key.GetValueNames();
        for (int i = 0; i < names.Length; i++)
            {
                Console.WriteLine(names[i]);
                byte[] test = ObjectToByteArray(key.GetValue(names[i]));
                var value = Convert.ToBase64String(test);
                Console.WriteLine(value);
            };

Normally the string value should be an encrypted binary.

Update: So as @Peter Lillevold suggested I had to convert the array of bytes into a string. To do so, I created this small function to convert the object key.GetValue into an array of bytes

public static byte[] ObjectToByteArray(Object obj)
        {
            if (obj == null)
                return null;
            BinaryFormatter Binaryform = new BinaryFormatter();
            MemoryStream MemStream = new MemoryStream();
            Binaryform.Serialize(MemStream, obj);
            return MemStream.ToArray();
        }

and then converted to a string as @Peter suggested.

So after the convertion of the array of bytes it is supposed to return me a string of binary. What I get is some weird combination of letters and digits but it is not binary.

Any help on this?

George H.
  • 87
  • 8

1 Answers1

-1

You get "System.Byte[]" because you take an instance of byte[] and calls ToString() on it. This will not convert the content of the byte array into text, for that you would use something like Convert.ToBase64String or Encoding.UTF8.GetString. More discussion on the topic in this SO question.

Community
  • 1
  • 1
Peter Lillevold
  • 33,668
  • 7
  • 97
  • 131
  • Actually string value = key.GetValue(names[i]); is counted as an object. However it's console write writes System.Bytes[] which means an array of bytes. The converts you suggested don't seem to work, or I am doing something wrong – George H. Jan 08 '15 at 21:56
  • Yes, as I said, the result of `key.GetValue` yields an object of type byte array. `Console.Write` does the same as you did, calling `ToString` on the byte array, which in turn only results in the text "System.Byte[]". So... what do you mean "don't seem to work" ? Show some code of what you have tried. Also, given a binary value in registry, show what text you require to end up with. – Peter Lillevold Jan 09 '15 at 08:56
  • Well, not exactly. You should be able to do `byte[] test = (byte[])key.GetValue(names[i]);` Next, I want you to show an example of what you expect as output. My example using `ToBase64String` will give you (surprise!) a base64 representation of the byte array. If this is not what you're after, you must tell us what yo mean by "string of binary". – Peter Lillevold Jan 09 '15 at 14:24
  • I wasn't able that is why I created that small function. I am able to do it now, I must have missed something in the beginning. If I am understanding correctly what your question here then, in that path are stored our IE credentials which we choose to be stored (and auto-filled obviously). I have important credentials which if I loose it will take time to get them back again (e-mail credentials, personal cards credentials). So my plans are: 1st to back them up, 2ond save them in a .txt file where they can be handled manually and re-written again to the registry. I hope this covers your answer. – George H. Jan 10 '15 at 17:20
  • Sorry for not responding immediately and thank you for bearing with me here – George H. Jan 10 '15 at 17:21
  • No worries. Well, I was more after what you expect the string to look like after you have converted the byte array to string. Like this, say, given this array [1,2,3, 255] I want the string to look like "010203FF". In essence, define your own requirement. – Peter Lillevold Jan 11 '15 at 18:47
  • Regardless of your coding problem, I would suggest you rather go to a commercial app, like 1password, which already does this in a highly secure manner. I would not trust myself to know all the necessary security knowledge related to storing passwords and other secrets. Note: I'm not in any way affiliated with 1password, I'm just a satisfied end-user :) – Peter Lillevold Jan 11 '15 at 18:50
  • It actually is a project so involving a third party application isn't much what I want to do. It should look like a binary: 0x01000000D08C9DDF01. This is not my final goal. I want it in readable letters so a normal user can understand it but this is too much to ask. – George H. Jan 11 '15 at 20:48
  • Well, then I would say you are trying to open a can of worms (http://en.wiktionary.org/wiki/can_of_worms). – Peter Lillevold Jan 11 '15 at 23:17
  • Sadly I know it but since there are applications that already do this, I thought that it wouldn't bother so much working on this project on public... – George H. Jan 13 '15 at 23:13