繁体   English   中英

如何从 iOS Objective-C 在 AWS 中生成签名?

[英]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];

有不同的方式来创建Authorization

  1. 借助AWS 开发工具包
  2. 借助这里的开源代码共享

对于 AWS SDK,下面的功能会有所帮助

AWSSignatureV4Signer.getCanonicalizedRequest
AWSSignatureSignerUtility.hexEncode
AWSSignatureV4Signer.getV4DerivedKey
AWSSignatureSignerUtility.sha256HMac

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM