[英]AWS SNS Get Certificate and Private key from .p12 file for Apple APNS
我正在尝试在SNS上创建一个平台应用程序,并且可以轻松地为GCM / Google Push服务执行此操作,但我遇到了Apple问题。
似乎当我调用CreatePlatformApplication()并传递请求时,我需要具有PlatformCredential和PlatformPrincipal这是证书和私钥。
AWS文档中针对应用程序的代码示例
var snsClient = new AmazonSimpleNotificationServiceClient();
var request = new CreatePlatformApplicationRequest
{
Attributes = new Dictionary<string, string>() { { "PlatformCredential", "AIzaSyDM1GHqKEdVg1pVFTXPReFT7UdGEXAMPLE" } },
Name = "TimeCardProcessingApplication",
Platform = "GCM"
};
snsClient.CreatePlatformApplication(request);
我当前在系统上有一个.p12文件,它与我们的手动系统一起用来发送推送通知,并且尝试过多次从p12文件中获取证书和私钥但是在发送请求时仍然收到错误说明PlatformPrincipal是无效的。
任何人都有想法如何从.p12文件中获取正确的PlatformPrincipal和PlatformCredential?
文档
在C#中没有简单的方法,因为它需要导出为ASN'1格式,但您可以使用OpenSSL:
私钥
openssl pkcs12 -in key.p12 -nodes -nocerts -passin pass: > private.txt
公钥
openssl pkcs12 -in key.p12" -nodes -nokeys -passin pass: > public.txt
然后发送到AWS SNS
string publicKey = File.ReadAllText("public.txt");
string privateKey = File.ReadAllText("private.txt");
using (var client = new AmazonSimpleNotificationServiceClient())
{
var request = new CreatePlatformApplicationRequest()
{
Name = Client,
Platform = TargetPlatform,
Attributes =
new Dictionary<string, string>()
{
{"PlatformCredential", privateKey },
{"PlatformPrincipal", publicKey }
}
};
var response = client.CreatePlatformApplication(request);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.