Wednesday, July 13, 2011

CryptographicException APNS

[CryptographicException: An internal error occurred.
]
   System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr) +33
   System.Security.Cryptography.X509Certificates.X509Utils._LoadCertFromBlob(Byte[] rawData, IntPtr password, UInt32 dwFlags, Boolean persistKeySet, SafeCertContextHandle& pCertCtx) +0
   System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromBlob(Byte[] rawData, Object password, X509KeyStorageFlags keyStorageFlags) +203
   System.Security.Cryptography.X509Certificates.X509Certificate..ctor(Byte[] rawData, String password) +80
   System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(Byte[] rawData, String password) +79
   JdSoft.Apple.Apns.Notifications.NotificationConnection.start(String p12File, String p12FilePassword) +224
   JdSoft.Apple.Apns.Notifications.NotificationService.set_Connections(Int32 value) +119
   JdSoft.Apple.Apns.Notifications.NotificationService..ctor(Boolean sandbox, String p12File, String p12FilePassword, Int32 connections) +211
   APN.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\iPhone\APN.aspx.cs:51
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
   System.Web.UI.Control.OnLoad(EventArgs e) +91
   System.Web.UI.Control.LoadRecursive() +74
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207
----
use code in NotificationConnection.cs: 

//certificate = new X509Certificate2(System.IO.File.ReadAllBytes(p12File), p12FilePassword);
certificate = new X509Certificate2(System.IO.File.ReadAllBytes(p12File), p12FilePassword, X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable);

2 comments:

  1. Tajen,

    I'm getting an error similar to this while attempting to use APNS with a shared hosting account.

    What is the scenario where you were running into this?

    ReplyDelete
  2. don't remember exactly what was the problem, but it was related moving the APNS from development to production. I believe I also changed the IIS 7, application pool identity to LocalService at that moment.

    Currently I'm using MoonAPNS instead.

    ReplyDelete