将对象转换为字节[]
我正在尝试将检索到的注册表值从 object
转换为 byte[]
。它存储为REG_BINARY
。我尝试将 BinaryFormatter
与 MemoryStream
一起使用。但是,它添加了我不想要的开销信息。当我通过执行函数 Convert.ToBase64String(..)
将字节数组转换为字符串时,我观察到了这一点。我执行这些功能是因为我正在测试注册表中加密密钥的存储和检索。
I am trying to convert a retrieved registry value from object
to byte[]
. It is stored as REG_BINARY
. I tried using BinaryFormatter
with MemoryStream
. However, it adds overhead information that I do not want. I observed this when I then converted the byte array to a string by performing the function Convert.ToBase64String(..)
. I am performing these functions because I am testing the storing and retrieval of an encrypted key in the registry.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果它是 REG_BINARY,那么当您检索它时,它应该已经是一个字节数组...难道您不能将其转换为
byte[]
吗?或者,如果您尚未验证代码中的REG_BINARY,您可能需要使用:
If it's a REG_BINARY then it should already be a byte array when you retrieve it... can't you just cast it to
byte[]
?Alternatively, if you haven't already verified that it's REG_BINARY in the code, you may want to use:
试试这个。如果它已经是 REG_BINARY,您需要做的就是转换它:
Try this. If it already is a REG_BINARY, all you need to do is cast it:
如果您使用 Convert.ToBase64String 转换它,您应该能够类似地得到它。
If you converted it using Convert.ToBase64String, you should be able to get it out similarly.