ios - 如何将 Google PRIVATE_KEY 转换为 Base64 编码签名
问题描述
我如何将 google 转换Private_key
为Base64 Encoded Signature
. 我在objective-c中做了同样的实现,但是我在swift中找不到同样的实现。拜托,任何人都可以帮助我...在此先感谢
NSString *key = keys.gOOGLE_PRIVATE_KEY;
NSString *url = [NSString stringWithFormat:@"/maps/api/directions/json?%@&sensor=false&client=%@", query, keys.gOOGLE_CLIENT_ID];
// Stores the url in a NSData.
NSData *urlData = [url dataUsingEncoding:NSUTF8StringEncoding];
// URL-safe Base64 coder/decoder.
GTMStringEncoding *encoding = [GTMStringEncoding rfc4648Base64WebsafeStringEncoding];
// Decodes the URL-safe Base64 key to binary.
NSData *binaryKey = [encoding decode:key];
// Signs the URL.
unsigned char result[CC_SHA1_DIGEST_LENGTH];
CCHmac(kCCHmacAlgSHA1,
[binaryKey bytes], [binaryKey length],
[urlData bytes], [urlData length],
&result);
NSData *binarySignature = [NSData dataWithBytes:&result length:CC_SHA1_DIGEST_LENGTH];
// Encodes the signature to URL-safe Base64.
NSString *signature = [encoding encode:binarySignature];
解决方案
推荐阅读
- php - Google Storage PHP 客户端:无法通过发布到签名 URL 来创建对象
- javascript - Remove div block and replace it by another
- java - 为什么 CDI 中不继承生产者
- python - QTableModel 对齐标题
- sql - 在 MariaDb 10.1 下运行此查询的替代方案
- pandas - 选择至少 X 列与条件 pandas 匹配的行
- javascript - Angular 6主题没有捕捉订阅事件?
- apache-kafka - KAFKA Cassandra 源连接
- python - python无法将输入数组从形状(144,291,3)广播到形状(140,300,3)
- angular-cli - npm WARN tar EPERM:不允许操作,打开