[具有十六进制值的c#WebConfig应用程序设置

问题描述 投票:0回答:1

我有以下c#代码行:

Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 });

我需要在web.config中存储十六进制值列表:

<add key="BytesVector" value="0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76" />

然后使用这样的值:

 var vector = ConfigurationManager.AppSettings["BytesVector"].ToString();

 Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, new byte[] { someParsingHere(vector) });

任何线索?

c# hex appsettings
1个回答
1
投票
这里是一个例子:

string s = "0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76"; var list = s.Split(','); byte[] bytes = new byte[list.Length]; for(int i=0; i<list.Count(); i++) { bytes[i] = Convert.ToByte(number.Trim(), 16); }

© www.soinside.com 2019 - 2024. All rights reserved.