AWS SNS从.p12文件中获取Apple APNS的证书和私钥 [英] AWS SNS Get Certificate and Private key from .p12 file for Apple APNS
本文介绍了AWS SNS从.p12文件中获取Apple APNS的证书和私钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在SNS上创建一个平台应用程序,并且可以轻松地为GCM/Google推送服务执行此操作,但我与Apple之间遇到了问题。
当我调用CreatePlatformApplication()并传递请求时,我似乎需要具有PlatformCredential和Platformain,这是证书和私钥。
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文件中获取证书和私钥,但在发送请求时仍收到错误,指出PlatformRule无效。
有谁知道如何从.p12文件中获取正确的PlatformMaster和PlatformCredential?
Documentation
推荐答案
在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);
}
这篇关于AWS SNS从.p12文件中获取Apple APNS的证书和私钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文