2

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.

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

Any help would be hugely appreciated.

creeperspeak
  • 5,403
  • 1
  • 17
  • 38
  • First, if you could link to the docs that would be good. Second, signing something with your secret key is how others are able verify that your request. The signing process is much like the encryption process, but where you normally use a public key in encryption, you would instead use your private key. Maybe look at https://en.wikipedia.org/wiki/Public-key_cryptography – hdost Dec 09 '15 at 22:14

1 Answers1

1

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.

Another way to go is CocoaPods OAuth.

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
}

// Test:

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

Output:

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

zaph
  • 111,848
  • 21
  • 189
  • 228