将 NSString 转换为二进制字符串
我有一个 NSString 表示一些数据的 sha1 哈希值,我需要将其转换为二进制字符串,但找不到任何好的解决方案来做到这一点。应该相当于PHP的pack函数。
结果应该是这样的:0xb7、0xc7、0x91、...、0x90。
我需要将此二进制文件转换为 Base64 编码的字符串。
I have a NSString representing sha1 hash of some data and I need to convert it to binary string, but cant find any good solution to do that. It should be equivalent to PHP's pack function.
The result should be like this: 0xb7, 0xc7, 0x91, ..., 0x90.
I than need to convert this binary to base64-encoded string.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
NSString+Base64
目录轻松地做到这一点。代码应该是这样的:
这是 NSString+Base64.h 文件的代码,例如:
和 NSString+Base64.m 文件:
You can easily to do so with a
NSString+Base64
catalog.And the code should like this:
Here is the Code of NSString+Base64.h file for example:
And the NSString+Base64.m file: