1

I have a developer key

 byte[] key = new Byte[]
            {
                0x01, 0x42, 0xA0, 0xE1, 0x5E, 0xEE, 0xA7, 0x01, 0x71, 0x9A, 0xCB, 0xAB, 0x58, 0xEB, 0xED, 0x44...

that I want to store in my web.config, can I do something like as follows

<add key="spotify-devkey" value="0x01, 0x42, 0xA0, 0xE1, 0x5E, 0xEE, 0xA7, 0x01, 0x71, 0x9A, 0xCB, 0xAB, 0x58, 0xEB, 0xED, 0x44,...

and if I can do it this easily what code would I need to get the byte array from the stored string?

1

2 Answers 2

11

I would use Base64

System.Convert.ToBase64String(key,0,key.Length);

and

System.Convert.FromBase64String(keyStringFromConfig);

to help keep the config file 'clean'

Sign up to request clarification or add additional context in comments.

1 Comment

+1 I recommend saving as a base 64 and converting back as well, much cleaner solution.
4
string value = ... // value from config file.
byte[] key = value.Split(new[] {','}).Select(s => Convert.ToByte(s, 16))
                                     .ToArray();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.