Objective-C:解码签名请求
如何在 Objective-C 中解码签名请求?
基本上,我如何将这个 Ruby 代码转换为 Objective-C 或 C?
# Facebook sends a signed_requests to authenticate certain requests.
# http://developers.facebook.com/docs/authentication/signed_request/
def decode_signed_request(signed_request)
encoded_signature, encoded_data = signed_request.split('.')
signature = base64_url_decode(encoded_signature)
expected_signature = OpenSSL::HMAC.digest('sha256', @secret, encoded_data)
if signature == expected_signature
JSON.parse base64_url_decode(encoded_data)
end
rescue Exception => e
puts $!, $@
end
def base64_url_decode(string)
"#{string}==".tr("-_", "+/").unpack("m")[0]
end
SSToolKit Base64 解码 NSString 看起来很有帮助。
How do I decode a signed request in Objective-C?
Basically, how do I translate this Ruby code to Objective-C or C?
# Facebook sends a signed_requests to authenticate certain requests.
# http://developers.facebook.com/docs/authentication/signed_request/
def decode_signed_request(signed_request)
encoded_signature, encoded_data = signed_request.split('.')
signature = base64_url_decode(encoded_signature)
expected_signature = OpenSSL::HMAC.digest('sha256', @secret, encoded_data)
if signature == expected_signature
JSON.parse base64_url_decode(encoded_data)
end
rescue Exception => e
puts $!, $@
end
def base64_url_decode(string)
"#{string}==".tr("-_", "+/").unpack("m")[0]
end
SSToolKit Base64 decode NSString looks helpful.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您想验证数据上的签名还是只是“解码”它?如果是后者,您可以忽略签名:
我使用 Facebook SDK 并选择合适的 JSON 框架(我推荐 JSONKit)由你决定。
您的评论表明您想要验证消息中包含的 HMAC。在这种情况下:
Do you want to verify the signature on the data or just "decode" it? If it's the latter, you can just ignore the signature:
I leave using the Facebook SDK and choosing a suitable JSON framework (I recommend JSONKit) up to you.
Your comment indicates that you want to verify the HMAC included with the message. In that case: