Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CryptographicException in WCF with PushSharp

I have a WCF service to send push notification to IOS device using APNS. I use the following code with using PushSharp.

I got an error at the "RegisterAppleService" step. The error explanation is: "CryptographicException was unhandled by user code The parameter is incorrect."

    private static PushBroker push;

    public string SendNotification()
    {
        push = new PushBroker();
        push.OnNotificationSent += NotificationSent;
        push.OnChannelException += ChannelException;
        push.OnServiceException += ServiceException;
        push.OnNotificationFailed += NotificationFailed;
        push.OnDeviceSubscriptionExpired += DeviceSubscriptionExpired;
        push.OnDeviceSubscriptionChanged += DeviceSubscriptionChanged;
        push.OnChannelCreated += ChannelCreated;
        push.OnChannelDestroyed += ChannelDestroyed;

        var appleCert = File.ReadAllBytes("CERT_FILE_NAME.p12");
        push.RegisterAppleService(new ApplePushChannelSettings(appleCert, "PASSWORD"));

        string devToken = "DEVICE_TOKEN";
        push.QueueNotification(new AppleNotification()
                                   .ForDeviceToken(devToken)
                                   .WithAlert("Hello World!")
                                   .WithBadge(7)
                                   .WithSound("sound.caf"));

I couldn't find the reason of the problem. How can I handle that exception? Thank you.

like image 224
erbileren Avatar asked Sep 01 '26 01:09

erbileren


1 Answers

I suspect that you are using only the key generated with the signing request and not the certificate itself.

https://github.com/Redth/PushSharp/wiki/How-to-Configure-&-Send-Apple-Push-Notifications-using-PushSharp

The steps are provided here, on step 18 be sure that you are exporting your certificate that is associated with the key and not just the key itself.

Also be sure that you are using development/sandbox ssl certificate for the development phase.

like image 90
Sarp Solakoglu Avatar answered Sep 03 '26 11:09

Sarp Solakoglu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!