如何将字节流转换为文本字符串?
我正在为我的应用程序开发许可系统。我想将所有许可信息(被许可人名称、到期日期和启用的功能)放入一个对象中,使用私钥加密该对象,然后将加密的数据表示为单个文本字符串,我可以通过电子邮件将其发送到我的顾客。
我已设法将加密数据转换为字节流,但我不知道如何将该字节流转换为文本值 - 不包含控制字符或空格的文本值。任何人都可以提供有关如何做到这一点的建议吗?我一直在研究 Encoding 类,但找不到纯文本编码。
我使用的是 Net 2.0——主要是 VB,但我也可以使用 C#。
I'm working on a licensing system for my application. I'd like to put all licensing information (licensee name, expiration date, and enabled features) into an object, encrypt that object with a private key, then represent the encrypted data as a single text string which I can send via email to my customers.
I've managed to get the encrypted data into a byte stream, but I don't know how to convert that byte stream into a text value -- something that contains no control characters or whitespace. Can anyone offer advice on how to do that? I've been researching the Encoding class, but I can't find a text-only encoding.
I'm using Net 2.0 -- mostly VB, but I can do C# also.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用 Base64Encoder 将其转换为可以使用 Base64Decoder 解码的文本字符串。它非常适合以文本友好的方式表示任意二进制数据,仅包含大小写 AZ 和 0-9 数字。
Use a Base64Encoder to convert it to a text string that can be decoded with a Base64Decoder. It is great for representing arbitary binary data in a text friendly manner, only upper and lower case A-Z and 0-9 digits.
BinHex 是一种方法的示例。它可能不完全是您想要的 - 例如,您可能希望对数据进行编码,以便不可能无意中拼写字符串中的单词,并且您可能关心也可能不关心最大化信息密度。但这是一个可以帮助您提出自己的编码的示例。
BinHex is an example of one way to do that. It may not be exactly what you want -- for example, you might want to encode your data such that it's impossible to inadvertently spell words in your string, and you may or may not care about maximizing the density of information. But it's an example that may help you come up with your own encoding.
我之前发现 Base32 对于许可证密钥很有用。 此答案链接了一些 C# 实现。我自己的许可证代码基于此实现,避免出现不明确的字符,从而更容易重新键入按键。
I've found Base32 useful for license keys before. There are some C# implementations linked from this answer. My own license code is based on this implementation, which avoids ambiguous characters to make it easier to retype the keys.