Hi, We're developing an ios app (swift programming) that should write usage data on a Google Spreadsheet. We don't want the user to sign-in for access to the sheet, that's why we got a Service Account from Google. But at this moment we're stuck trying to get a SecKey from the private key Google gave us.
Our first attempt was trying to find a library (and documentation) in order to not reinvent the wheel, but we didn't find one or didn't understand how to use it (We have been trying AppAuth but the usage examples always ask for a user sign-in. So, we start to write code for HTTP/REST authorized api call (As it stands in https://developers.google.com/identity/protocols/OAuth2ServiceAccount ), but for computing the signature we're getting an error when trying to get a SecKey from the private key Google gave us. This is code from a Playground showing the problem: let privateKey = "MIIEv....qgWKa+VH6w==" // privateKey has many more characters (1649 characters in total) let privateKeyData = privateKey.data(using: String.Encoding.utf8) let base64privateKeyData = privateKeyData?.base64EncodedData() // We tried different values of kSecAttrKeySizeInBits (256, 512, 1024, 2048 and 4096) an none of them worked let keyDict:[NSObject:NSObject] = [ kSecAttrKeyType: kSecAttrKeyTypeRSA, kSecAttrKeyClass: kSecAttrKeyClassPrivate, kSecAttrKeySizeInBits: NSNumber(value: 4096), kSecReturnPersistentRef: true as NSObject ] let cfData = base64privateKeyData! as CFData var error: Unmanaged<CFError>? let publicKey = SecKeyCreateWithData(cfData, keyDict as CFDictionary, &error ) NSLog(error.debugDescription) The log output is as follows: *2017-09-21 18:53:00.301 OAuthPlayground[32447:7458540] Optional(Swift.Unmanaged<__ObjC.CFError>(_value: Error Domain=NSOSStatusErrorDomain Code=-50 "RSA private key creation from data failed" UserInfo={NSDescription=RSA private key creation from data failed}))* Can anyone help us, please. Thanks, Fernando -- You received this message because you are subscribed to the Google Groups "Google Spreadsheets API" group. To unsubscribe from this group and stop receiving emails from it, send an email to google-spreadsheets-api+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.