我正在尝试在 SNS 上创建一个平台应用程序,并且可以轻松地为 GCM/Google 推送服务创建它,但我在使用 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);
}
关于c# - AWS SNS 从 Apple APNS 的 .p12 文件中获取证书和私钥,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36343804/