Skip to content

Chrome/Mozilla push notifications payload encryption for .NET

Notifications You must be signed in to change notification settings

LogicSoftware/WebPushEncryption

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Web Push Encryption

Chrome/Mozilla push notifications payload encryption for .NET

Installation

LogicSoftware.WebPushEncryption can be installed via the nuget UI (as WebPushEncryption), or via the nuget package manager console:

PM> Install-Package WebPushEncryption

Usage

using LogicSoftware.WebPushEncryption;

//------------------------------------

var encryptedPayload = Encryptor.Encrypt(p256dh, auth, payload);

HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, pushEndpoint);

// send encrypted payload instead of original
request.Content = new ByteArrayContent(encryptedPayload.Payload);
request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
request.Content.Headers.ContentLength = encryptedPayload.Payload.Length;

// append public key and salt as headers
request.Content.Headers.ContentEncoding.Add("aesgcm");
request.Headers.Add("Crypto-Key", "keyid=p256dh;dh=" + encryptedPayload.Base64EncodePublicKey());
request.Headers.Add("Encryption", "keyid=p256dh;salt=" + encryptedPayload.Base64EncodeSalt());