NSData 到 NSString,反之亦然
系统会提示我的用户输入 RAW NSData(例如:<0201581d 9fc84f7b bf136a80 e7fc9572>)
此原始数据是 AES 加密的 NSString。
然而,问题是将那些实际的数据字节 <0201581d 9fc84f7b bf136a80 e7fc9572> 转换为转换为 NSData 类型本身。
- 提示输入数据
- 输入数据 --> @“<0201581d 9fc84f7b bf136a80 e7fc9572>”
- 需要将输入的数据转换为 NSData 类型,而不是传递的 NSString 类型。
简而言之;我该怎么做:<0201581d 9fc84f7b bf136a80 e7fc9572>进入 NSData 的数据? 让一个整数保存数据的一半是有效的(因为类型太短),所以它需要是一个 NSString。
My user is prompted to enter in RAW NSData (like: <0201581d 9fc84f7b bf136a80 e7fc9572>)
This raw data is an AES encrypted NSString.
However, the issue is converting those actual bytes of data <0201581d 9fc84f7b bf136a80 e7fc9572> into an NSData type itself.
- Prompted to enter data
- Enters data --> @"<0201581d 9fc84f7b bf136a80 e7fc9572>"
- Needs to make entered data into an NSData type rather than the NSString which was passed.
In short; How do I make this: <0201581d 9fc84f7b bf136a80 e7fc9572> into the NSData's data?
Making an integer hold the data HALF works (because the type is too short) so It needs to be an NSString.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
要将十六进制字符串转换为数据,请参阅我在此处发布的函数:
在 Objective-C 中将十六进制字符串转换为二进制
您需要稍微修改它以允许括号字符和空格。
要走向另一个方向:
您还可以使用:
使用 -[NSData description] 来获取带有括号和空格的版本。
To convert a hexadecimal string to data, see the function that I posted here:
Converting a hexadecimal string into binary in Objective-C
You will want to modify it slightly to allow bracket characters and whitespace.
To go the other direction:
You can also use:
to use -[NSData description] to get a version with the brackets and spaces.
这与NSString(十六进制)到字节非常相似。如果您删除多余的标点符号,答案将会对您有用。
This is extremely similar to NSString (hex) to bytes. The answer there will work for you if you remove the excess punctuation.
要将 NSData 转换为 NSString 使用:
将 NSString 转换为 NSData 使用:
To convert NSData to NSString use :
To convert NSString to NSData use :