Yelp API OAuth - oauth_signature [英] Yelp API OAuth - oauth_signature

查看:72
本文介绍了Yelp API OAuth - oauth_signature的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 Swift iOS 应用程序中使用 Yelp API,但我不熟悉加密.我知道我应该用 SHA1 加密签名,但在 Swift/Xcode 中找不到这样做的好资源.

I am trying to use the Yelp API in a Swift iOS app, but am new to encryption. I understand that I am supposed to encrypt the signature with SHA1, but can't find good resources for doing this in Swift/Xcode.

此外,Yelp 文档说我应该将签名值传递为生成的请求签名,使用获得的 oauth_token_secret 签名".我不明白签名"是什么意思.链接到此处的文档:Yelp Authentication

Additionally, the Yelp docs say I am supposed to pass the signature value as "The generated request signature, signed with the oauth_token_secret obtained". I don't understand what is meant by "signed with". Link to the docs here: Yelp Authentication

任何帮助将不胜感激.

推荐答案

更新:看看 CocoaPods YELP 解决方案,您可以选择使用 CocoaPod、直接嵌入代码或仅使用代码作为示例.

Update: Take a look at CocoaPods YELP solutions, you have options of using a CocoaPod, directly embedding the code or just using the code as an example.

另一种方法是CocoaPods OAuth.

SHA1 不是加密,它是一个哈希函数,为其输入创建一个 20 字节的签名.

SHA1 is not encryption, it is a hash function that creates a 20-byte signature for it's input.

这是一个可能有用但可能不符合您的输入和输出数据格式的示例:

Here is an example that may be useful but may not meet your inpout and output data formats:

func sha1(string string: String) -> [UInt8] {
    var digest = [UInt8](count: Int(CC_SHA1_DIGEST_LENGTH), repeatedValue: 0)
    if let data = string.dataUsingEncoding(NSUTF8StringEncoding) {
        CC_SHA1(data.bytes, CC_LONG(data.length), &digest)
    }
    return digest
}

//测试:

let digest = sha1(string:"Here is the test string")
print("digest: \(digest)")

输出:

摘要:[143, 131, 57, 51, 3, 161, 81, 234, 51, 191, 110, 62, 187, 194, 133, 148]

digest: [143, 131, 57, 51, 3, 161, 81, 234, 51, 191, 110, 62, 187, 194, 133, 148]

这篇关于Yelp API OAuth - oauth_signature的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆