Cross-Platform Encryption And Decryption Using Android + IOS + Angular + NodeJS

Jay Sojitra
2 min readMay 23, 2021

Nowadays, Security is a big concern for every person. It is the main aspect in the world of software/web development. We need to make sure that while transmitting data from server to client, it’s safe and secure. We need to be sure that only the sender and receiver can read the data.

In this blog, we will cover below points:

  • Encrypt the file buffer at the server side (NodeJS)
  • Decrypt the file buffer at the client side (Android + IOS + Angular)

Let’s start…

A. Encrypt file buffer using NodeJS and Decrypt it in Android and IOS.

NOTE: Android supports the encryption key with the length of 32 bytes and IV must be 16 byte of length.

  • To generate the encryption key and IV use the following code:
  1. Encrypt file buffer in NodeJS using the crypto module.

2.1 Decrypt the encrypted base64 buffer in Android:

2.2 Decrypt the file buffer in IOS:

B. Encrypt file buffer using NodeJS and Decrypt it in Angular.

In angular, I had to use crypto-js npm module. Because using crypto npm, I am not able to decrypt the buffer in Angular. Crypto-js is not built in module of NodeJS or Angular, So you need to intall it using npm install crypto-js -S.

  1. Encrypt the buffer using crypto-js npm in NodeJS.

2. Decrypt the file buffer in Angular using crypto-js:

2.1 _arrayBufferToBase64(getBuffer) method will convert buffer to base64. Here is the code for that function:

Summary:

Encryption and decryption depends on encryption type (AES-256-CTR), encryption key and iv (initialization vector) and not on programming language. That’s why, encrypted string from node.js can be decrypted in C#/java, swift and Angular provided encryption type, encryption key and iv should be same.

--

--