Git Product home page Git Product logo

encrypted-push-notification's Introduction

Push notification

This example code shows how to encrypt a push notification content and send it to a device. It uses RSA and AES encryption algorithms to encrypt the data.

With AES the data is encrypted and with RSA publickey the AES is encrypted and send to the devices. The client receives the encrypted data along with encrypted AES key. Since the client has the RSA privatekey, it can decrypt the AES key. Thereafter, it uses the AES key to decrypt the data and shows the content to the user.

Steps to encrypt

  1. Server knows the RSA publickey and push notification token
  2. Server generates an AES key
val aesKey = cryptoManager.generateAESkey()
  1. Server encrypts the data with AES key (CryptoManager.decryptSymmetric)
val payloadEncryptedResult = cryptoManager.encryptSymmetric(payloadStr, aesKey)
  1. Server encrypts the AES key with RSA publickey (CryptoManager.decryptAsymmetric)
val encryptedAesKeyResult = cryptoManager.encryptAsymmetric(encodedAesKeyStr, publicKey)
  1. Server sends message to device with push notification token

CryptoManager can also be used to decrypt the content in Android

Steps to decrypt

  1. Once the push notification is received, get the encrypted AES key from the received data
  2. Since the device has the RSA privatekey, it can decrypt the AES key
val privateKey = PRIVATE_KEY
val decryptedAesKeyResult = cryptoManager.decryptAsymmetric(encryptedAesKey, privateKey)
  1. Use the decryptedAesKey to decrypt the message
val messageResult = cryptoManager.decryptSymmetric(cipherData, encodedAesKeyStr)

Data structure

You can use your own data set. In this example we use the following data

{
  "encrypted-content": {
    "version": "string",
    "title": "fallback title",
    "message": "fallback message",
    "type": "notification type (if needed)",
    "key": "encrypted symmetric key (AES). This key is encrypted with the asymmetic publickey",
    "payload": "encrypted push message data. This is encrypted using the symmetic AES key"
  }
}

//Data structure of encrypted content
{
  "title": "encrypted title",
  "message": "encrypted message",
  "type": "notification type (if needed)",
  "url": "Deeplink which describes what to do after the notification is opend"
}

How to run locally

Run the main method, it will start a Ktor server http://localhost:8222

encrypted-push-notification's People

Contributors

bakhtarsobat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.