简体   繁体   English

推送Sharp ios通知,获取分发证书“ System.Security.Cryptography.CryptographicException”的错误

[英]Push Sharp ios notification getting error with distribution certificate “System.Security.Cryptography.CryptographicException”

I am working on apple push notification using Push Sharp. 我正在使用Push Sharp处理苹果推送通知。 It's working good on my local machine with development and distribution certificates. 带有开发和发行证书的本地计算机上运行良好。 I did receive push notification when i tried locally. 我在本地尝试时确实收到了推送通知。 But, When I moved the code to my production server (GODaddy server), I am receiving an error 但是,当我将代码移到生产服务器(GODaddy服务器)时,我收到一个错误

System.Security.Cryptography.CryptographicException).

PushBroker _pushBroker = new PushBroker();
                var appleCert = File.ReadAllBytes(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Certificates/App_AdHoc.p12"));
                _pushBroker.RegisterAppleService(new ApplePushChannelSettings(true, appleCert, "pamten")); //Extension method
                _pushBroker.QueueNotification(new AppleNotification()
                        .ForDeviceToken("Device Token")
                        .WithAlert("Message")
                        .WithBadge(0)
                        .WithSound("default")
                        );

Below is the error i am getting in GoDaddy server. 以下是我在GoDaddy服务器中遇到的错误。

ExceptionType": "System.Security.Cryptography.CryptographicException",
5   "StackTrace": " at System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr)\r\n at System.Security.Cryptography.X509Certificates.X509Utils._LoadCertFromBlob(Byte[] rawData, IntPtr password, UInt32 dwFlags, Boolean persistKeySet, SafeCertContextHandle& pCertCtx)\r\n at System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromBlob(Byte[] rawData, Object password, X509KeyStorageFlags keyStorageFlags)\r\n at System.Security.Cryptography.X509Certificates.X509Certificate..ctor(Byte[] rawData, String password, X509KeyStorageFlags keyStorageFlags)\r\n at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(Byte[] rawData, String password, X509KeyStorageFlags keyStorageFlags)\r\n at PushSharp.Apple.ApplePushChannelSettings..ctor(Boolean production, Byte[] certificateData, String certificateFilePwd, Boolean disableCertificateCheck)\r\n at InStorePal.Controllers.InStorePalController.GetItemsList(GetItems obj)\r\n at lambda_method(Closure , Object , Object[] )\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass13.<GetExecutor>b__c(Object instance, Object[] methodParameters)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.<>c__DisplayClass5.<ExecuteAsync>b__4()\r\n at System.Threading.Tasks.TaskHelpers.RunSynchronously[TResult](Func`1 func, CancellationToken cancellationToken)"
6   }

I have tried lot of ways like access permissions for the folders in GODaddy server, created distributed certificates so many times. 我尝试了很多方法,例如对GODaddy服务器中文件夹的访问权限,创建分布式证书这么多次。

Please help me. 请帮我。 . .

I was facing the same issue in GoDaddy Server. 我在GoDaddy服务器中也遇到了同样的问题。 Try Azure or Amazon server once. 尝试一次Azure或Amazon服务器。 It worked for me in Azure. 它在Azure中为我工作。

Its a strange issue and strange solution. 这是一个奇怪的问题和奇怪的解决方案。 But it worked for me. 但这对我有用。

 public ActionResult ios()
    {
        var certi = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Certificatesgit.p12");
        var appleCert = System.IO.File.ReadAllBytes(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Certificatesgit.p12"));

        ApnsConfiguration apnsConfig = new ApnsConfiguration(ApnsConfiguration.ApnsServerEnvironment.Production, appleCert, "password");

        string message = string.Empty;
        var apnsBroker = new ApnsServiceBroker(apnsConfig);

        apnsBroker.OnNotificationFailed += (notification, aggregateEx) =>
        {
            aggregateEx.Handle(ex =>
            {
                if (ex is ApnsNotificationException)
                {
                    var notificationException = (ApnsNotificationException)ex;
                    var apnsNotification = notificationException.Notification;
                    var statusCode = notificationException.ErrorStatusCode;
                    var inner = notificationException.InnerException;
                    message = "IOS Push Notifications: Apple Notification Failed: ID=" + apnsNotification.Identifier + ", Code=" + statusCode + ", Inner Exception" + inner;
                }
                else
                {
                    message = "IOS Push Notifications: Apple Notification Failed for some unknown reason : " + ex.InnerException;
                }
                return true;
            });
        };

        apnsBroker.OnNotificationSucceeded += (notification) =>
        {
            message = "IOS Push Notifications: Apple Notification Sent!";
        };

        apnsBroker.Start();
        try
        {
            string deviceToken = "4e16e1439d7f1a342ed5a8c92bf029503107c7a2bc3b92b794b22665affcf99c";

            apnsBroker.QueueNotification(new ApnsNotification
            {
                DeviceToken = deviceToken,
                Payload = JObject.Parse("{\"aps\":{\"badge\":7}}")
            });
        }
        catch (Exception ex)
        {
            Console.Write(ex);
        }
        apnsBroker.Stop();

        return View(message);
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TwilioRequestValidator 中的瞬态 System.Security.Cryptography.CryptographicException - Transient System.Security.Cryptography.CryptographicException in TwilioRequestValidator System.Security.Cryptography.CryptographicException:句柄无效 - System.Security.Cryptography.CryptographicException: The handle is invalid System.Security.Cryptography.CryptographicException:参数不正确 - System.Security.Cryptography.CryptographicException: The parameter is incorrect System.Security.Cryptography.CryptographicException:'Cryptography_OAEPDecoding' - System.Security.Cryptography.CryptographicException: 'Cryptography_OAEPDecoding' Azure Web应用程序新X509Certificate2()导致System.Security.Cryptography.CryptographicException:访问被拒绝 - Azure Web Application new X509Certificate2() causing System.Security.Cryptography.CryptographicException: Access denied System.Security.Cryptography.CryptographicException:系统找不到指定的文件 - System.Security.Cryptography.CryptographicException: The system cannot find the file specified 重置Microsoft Identity上的密码会导致System.Security.Cryptography.CryptographicException - Resetting password on Microsoft Identity causes System.Security.Cryptography.CryptographicException PrivateKey抛出了System.Security.Cryptography.CryptographicException类型的异常 - PrivateKey threw an exception of type System.Security.Cryptography.CryptographicException System.Security.Cryptography.CryptographicException:'输入数据不是一个完整的块。' - System.Security.Cryptography.CryptographicException: 'The input data is not a complete block.' System.Security.Cryptography.CryptographicException:密钥集不存在 - System.Security.Cryptography.CryptographicException: keyset does not exist
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM