PushSharp 抛出 CryptographicException:证书实例为空
PushSharp throwing CryptographicException: Certificate instance is empty
我无法让 PushSharp 工作,我很确定问题出在我做错了什么,尽管我不知道是什么...:/
代码如下:
var cert = new X509Certificate2(
"cio_aps_development.p12",
"",
X509KeyStorageFlags.MachineKeySet |
X509KeyStorageFlags.PersistKeySet |
X509KeyStorageFlags.Exportable);
//var config = new ApnsConfiguration(ApnsConfiguration.ApnsServerEnvironment.Sandbox, "cio_aps_development.p12", "");
var config = new ApnsConfiguration(ApnsConfiguration.ApnsServerEnvironment.Sandbox, cert);
无论我采用哪种方法,我都会收到此错误:
System.Security.Cryptography.CryptographicException: Certificate instance is empty.
System.Security.Cryptography.CryptographicException: Certificate instance is empty.
at System.Security.Cryptography.X509Certificates.X509Helper.ThrowIfContextInvalid (System.Security.Cryptography.X509Certificates.X509CertificateImpl impl) [0x0000b] in /private/tmp/source-mono-4.6.0/bockbuild-xamarin/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class/corlib/System.Security.Cryptography.X509Certificates/X509Helper.cs:120
at System.Security.Cryptography.X509Certificates.X509Certificate.get_Impl () [0x00000] in /private/tmp/source-mono-4.6.0/bockbuild-xamarin/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class/corlib/System.Security.Cryptography.X509Certificates/X509Certificate.cs:137
at System.Security.Cryptography.X509Certificates.X509Certificate2.get_Impl () [0x00000] in /private/tmp/source-mono-4.6.0/bockbuild-xamarin/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class/System/System.Security.Cryptography.X509Certificates/X509Certificate2.cs:63
at System.Security.Cryptography.X509Certificates.X509Certificate2.get_IssuerName () [0x00000] in /private/tmp/source-mono-4.6.0/bockbuild-xamarin/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class/System/System.Security.Cryptography.X509Certificates/X509Certificate2.cs:169
at PushSharp.Apple.ApnsConfiguration.CheckIsApnsCertificate () [0x00011] in <1389cefdb7bb4d6c97d6126934847d24>:0
at PushSharp.Apple.ApnsConfiguration.Initialize (PushSharp.Apple.ApnsConfiguration+ApnsServerEnvironment serverEnvironment, System.Security.Cryptography.X509Certificates.X509Certificate2 certificate, System.Boolean validateIsApnsCertificate) [0x000a8] in <1389cefdb7bb4d6c97d6126934847d24>:0
at PushSharp.Apple.ApnsConfiguration..ctor (PushSharp.Apple.ApnsConfiguration+ApnsServerEnvironment serverEnvironment, System.Security.Cryptography.X509Certificates.X509Certificate2 certificate) [0x00006] in <1389cefdb7bb4d6c97d6126934847d24>:0
有什么想法吗?
谢谢!
供日后参考:
问题出在我的 p12 文件上。它没有正确导出。
以正确的方式导出后,它成功了。
我无法让 PushSharp 工作,我很确定问题出在我做错了什么,尽管我不知道是什么...:/
代码如下:
var cert = new X509Certificate2(
"cio_aps_development.p12",
"",
X509KeyStorageFlags.MachineKeySet |
X509KeyStorageFlags.PersistKeySet |
X509KeyStorageFlags.Exportable);
//var config = new ApnsConfiguration(ApnsConfiguration.ApnsServerEnvironment.Sandbox, "cio_aps_development.p12", "");
var config = new ApnsConfiguration(ApnsConfiguration.ApnsServerEnvironment.Sandbox, cert);
无论我采用哪种方法,我都会收到此错误:
System.Security.Cryptography.CryptographicException: Certificate instance is empty.
System.Security.Cryptography.CryptographicException: Certificate instance is empty.
at System.Security.Cryptography.X509Certificates.X509Helper.ThrowIfContextInvalid (System.Security.Cryptography.X509Certificates.X509CertificateImpl impl) [0x0000b] in /private/tmp/source-mono-4.6.0/bockbuild-xamarin/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class/corlib/System.Security.Cryptography.X509Certificates/X509Helper.cs:120
at System.Security.Cryptography.X509Certificates.X509Certificate.get_Impl () [0x00000] in /private/tmp/source-mono-4.6.0/bockbuild-xamarin/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class/corlib/System.Security.Cryptography.X509Certificates/X509Certificate.cs:137
at System.Security.Cryptography.X509Certificates.X509Certificate2.get_Impl () [0x00000] in /private/tmp/source-mono-4.6.0/bockbuild-xamarin/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class/System/System.Security.Cryptography.X509Certificates/X509Certificate2.cs:63
at System.Security.Cryptography.X509Certificates.X509Certificate2.get_IssuerName () [0x00000] in /private/tmp/source-mono-4.6.0/bockbuild-xamarin/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class/System/System.Security.Cryptography.X509Certificates/X509Certificate2.cs:169
at PushSharp.Apple.ApnsConfiguration.CheckIsApnsCertificate () [0x00011] in <1389cefdb7bb4d6c97d6126934847d24>:0
at PushSharp.Apple.ApnsConfiguration.Initialize (PushSharp.Apple.ApnsConfiguration+ApnsServerEnvironment serverEnvironment, System.Security.Cryptography.X509Certificates.X509Certificate2 certificate, System.Boolean validateIsApnsCertificate) [0x000a8] in <1389cefdb7bb4d6c97d6126934847d24>:0
at PushSharp.Apple.ApnsConfiguration..ctor (PushSharp.Apple.ApnsConfiguration+ApnsServerEnvironment serverEnvironment, System.Security.Cryptography.X509Certificates.X509Certificate2 certificate) [0x00006] in <1389cefdb7bb4d6c97d6126934847d24>:0
有什么想法吗?
谢谢!
供日后参考:
问题出在我的 p12 文件上。它没有正确导出。 以正确的方式导出后,它成功了。