[英]How to generate signature in AWS from iOS objective-C?
请提供一些演示或示例以使用 iOS 生成签名。 https://docs.aws.amazon.com/general/latest/gr/signature-v4-examples.html链接在objective-c 中不包含任何示例。
您可以参考实现对请求进行签名的适用于 iOS 的 AWS 开发工具包。 这是使用 AWSCore 中的 AWSSignatureSignerUtility 的示例。
您可以通过 cocoapods 获取 AWSCore。 尝试
pod 'AWSCore'
在你的 Podfile 中。
NSString *aString = @"a random string";
NSString *secretKey = @"aKey";
//unsupport algorithm, should return nil
NSString *signature = [[AWSSignatureSignerUtility HMACSign:[aString dataUsingEncoding:NSUTF8StringEncoding]
withKey:secretKey
usingAlgorithm:kCCHmacAlgMD5] aws_stringWithURLEncoding];
有关 SDK 的更多信息: https : //docs.aws.amazon.com/mobile/sdkforios/developerguide/setup-aws-sdk-for-ios.html
NSString *aString = @"***********"; NSString *secretKey = @"*********";
NSURL *apiLink = [NSURL URLWithString:@"https://*********"];
AWSStaticCredentialsProvider *creds = [[AWSStaticCredentialsProvider alloc] initWithAccessKey: aString secretKey: secretKey ];
AWSEndpoint *url1 = [[AWSEndpoint alloc] initWithRegion: AWSRegionAPEast1 serviceName: @"APIGateway" URL: apiLink ];
AWSTask *sign = [AWSSignatureV4Signer generateQueryStringForSignatureV4WithCredentialProvider: creds httpMethod: AWSHTTPMethodGET expireDuration: 300 endpoint:url1 keyPath: @"***" requestHeaders:NULL requestParameters:NULL signBody:true];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.