C# AWS SNS从Apple APN的.p12文件中获取证书和私钥

C# AWS SNS从Apple APN的.p12文件中获取证书和私钥,c#,amazon-web-services,ssl,push-notification,amazon-sns,C#,Amazon Web Services,Ssl,Push Notification,Amazon Sns,我正在尝试在SNS上创建一个平台应用程序,可以很容易地为GCM/谷歌推送服务创建它,但我和苹果有问题 当我调用CreatePlatformApplication()并传递请求时,似乎需要有PlatformCredential和PlatformPrincipal,即证书和私钥 应用程序AWS文档中的代码示例 var snsClient = new AmazonSimpleNotificationServiceClient(); var request = new CreatePlatformAp

我正在尝试在SNS上创建一个平台应用程序,可以很容易地为GCM/谷歌推送服务创建它,但我和苹果有问题

当我调用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);
var snsClient=new AmazonSimpleNotificationServiceClient();
var请求=新建CreatePlatformApplicationRequest
{
Attributes=new Dictionary(){{“PlatformCredential”,“AIzaSyDM1GHqKEdVg1pVFTXPReFT7UdGEXAMPLE”},
Name=“TimeCardProcessingApplication”,
平台=“GCM”
};
snsClient.CreatePlatformApplication(请求);
我目前在系统上有一个.p12文件,该文件与我们的手动系统一起用于发送推送通知,并尝试了多次从p12文件中获取证书和私钥,但我在发送请求时仍然收到一个错误,称PlatformPrincipal无效

有人知道如何从.p12文件中获取正确的PlatformPrincipal和PlatformCredential吗

文档

var snsClient = new AmazonSimpleNotificationServiceClient();

var request = new CreatePlatformApplicationRequest
{
  Attributes = new Dictionary<string, string>() { { "PlatformCredential", "AIzaSyDM1GHqKEdVg1pVFTXPReFT7UdGEXAMPLE" } },
  Name = "TimeCardProcessingApplication",
  Platform = "GCM"
};

snsClient.CreatePlatformApplication(request);

在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
公钥

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);
}
string publicKey=File.ReadAllText(“public.txt”);
字符串privateKey=File.ReadAllText(“private.txt”);
使用(var client=new AmazonSimpleNotificationServiceClient())
{
var request=新建CreatePlatformApplicationRequest()
{
名称=客户,
平台=目标平台,
属性=
新字典()
{
{“PlatformCredential”,privateKey},
{“PlatformPrincipal”,公钥}
}
};
var response=client.CreatePlatformApplication(请求);
}