Skip to content

Commit 51139d9

Browse files
committed
Add new methods for the encryption
1 parent f8c391d commit 51139d9

File tree

13 files changed

+1482
-734
lines changed

13 files changed

+1482
-734
lines changed

.prettierrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"tabWidth": 2,
3+
"useTabs": false
4+
}

README.md

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ This guide explains how to directly access methods from the `rn-encryption` libr
77
## 📑 **Table of Contents**
88

99
1. [Library Installation](#1-library-installation)
10-
2. [New Architecture required](#2-new_arch_needed)
10+
2. [Requirements](#2-new_arch_needed)
1111
3. [Setup in React Native](#3-setup-in-react-native)
1212
4. [Direct Method Import](#4-direct-method-import)
1313
5. [API Overview](#5-api-overview)
1414
6. [Usage Examples](#6-usage-examples)
1515
7. [Troubleshooting](#7-troubleshooting)
1616
8. [Best Practices](#8-best-practices)
17-
9. [FAQ](#9-faq)
17+
9. [FAQ](#9-faq)
18+
10. [Security Best Practices](#security-best-practices)
1819

1920
---
2021

@@ -29,9 +30,6 @@ npm install rn-encryption --save
2930
# OR
3031
yarn add rn-encryption
3132
```
32-
### #2-new_arch_needed
33-
34-
New architecture required. React native >= 0.76.5 Works with Expo **Bare Workflow** & **Vanilla React Native**
3533

3634
### 1.2 **Rebuild the Project**
3735

@@ -47,15 +45,21 @@ cd ios && pod install && cd ..
4745
npx react-native run-ios
4846
```
4947

48+
---
49+
## **2.Requirements**
50+
### 2.1 **New Architecture required**
51+
New architecture required. React native >= 0.76.5 Works with Expo **Bare Workflow** & **Vanilla React Native**
52+
### 2.2 **iOS: Cryptokit from swift is being used for encryption. Minimin support iOS version is 13.0**
53+
5054
---
5155

52-
## ⚙️ **2. Setup in React Native**
56+
## ⚙️ **3. Setup in React Native**
5357

5458
No additional configuration is required. The methods can be **directly imported** and used.
5559

5660
---
5761

58-
## 📦 **3. Direct Method Import**
62+
## 📦 **4. Direct Method Import**
5963

6064
You can directly import the methods you need:
6165

@@ -78,7 +82,7 @@ Each method can be accessed directly without a default object wrapper.
7882

7983
---
8084

81-
## 📚 **4. API Overview**
85+
## 📚 **5. API Overview**
8286

8387
### 🔒 **AES Encryption/Decryption**
8488
- **`encryptAES(data: string, key: string): string`**
@@ -104,9 +108,9 @@ Each method can be accessed directly without a default object wrapper.
104108

105109
---
106110

107-
## 🛠️ **5. Usage Examples**
111+
## 🛠️ **6. Usage Examples**
108112

109-
### 🔒 **5.1 AES Encryption and Decryption**
113+
### 🔒 **6.1 AES Encryption and Decryption**
110114

111115
```tsx
112116
import { encryptAES, decryptAES } from 'rn-encryption';
@@ -131,7 +135,7 @@ runAESExample();
131135

132136
---
133137

134-
### 🔑 **5.2 RSA Encryption and Decryption**
138+
### 🔑 **6.2 RSA Encryption and Decryption**
135139

136140
```tsx
137141
import { encryptRSA, decryptRSA } from 'rn-encryption';
@@ -157,7 +161,7 @@ runRSAExample();
157161

158162
---
159163

160-
### 🛡️ **5.3 SHA Hashing**
164+
### 🛡️ **6.3 SHA Hashing**
161165

162166
```tsx
163167
import { hashSHA256, hashSHA512 } from 'rn-encryption';
@@ -177,7 +181,7 @@ runHashExample();
177181

178182
---
179183

180-
### 📝 **5.4 HMAC-SHA256**
184+
### 📝 **6.4 HMAC-SHA256**
181185

182186
```tsx
183187
import { hmacSHA256 } from 'rn-encryption';
@@ -195,7 +199,7 @@ runHMACExample();
195199

196200
---
197201

198-
### 🎲 **5.5 Random String Generation**
202+
### 🎲 **6.5 Random String Generation**
199203

200204
```tsx
201205
import { generateRandomString } from 'rn-encryption';
@@ -210,7 +214,7 @@ runRandomStringExample();
210214

211215
---
212216

213-
### 📝 **5.6 Base64 Encoding/Decoding**
217+
### 📝 **6.6 Base64 Encoding/Decoding**
214218

215219
```tsx
216220
import { base64Encode, base64Decode } from 'rn-encryption';
@@ -230,7 +234,7 @@ runBase64Example();
230234

231235
---
232236

233-
## 🐞 **6. Troubleshooting**
237+
## 🐞 **7. Troubleshooting**
234238

235239
1. **Library Not Found:**
236240
- Run `npx react-native link rn-encryption`.
@@ -247,15 +251,15 @@ runBase64Example();
247251

248252
---
249253

250-
## **7. Best Practices**
254+
## **8. Best Practices**
251255

252256
1. **Do Not Hardcode Keys:** Use `.env` or secure storage for keys.
253257
2. **Handle Errors Gracefully:** Wrap calls in `try-catch` blocks.
254258
3. **Validate Key Sizes:** Ensure AES and RSA keys meet size requirements.
255259

256260
---
257261

258-
## **8. FAQ**
262+
## **9. FAQ**
259263

260264
**Q: Does the library support both Android and iOS?**
261265
A: Partially, `rn-encryption` fully supports ios and encryptAES & decryptAES for Android platforms.
@@ -268,7 +272,27 @@ A: Add console logs and verify that keys and data are correctly passed.
268272

269273
---
270274

271-
## **9. Conclusion**
272-
273-
With **`rn-encryption`**, you can securely handle encryption, hashing, and cryptographic operations in your React Native app. Use the examples above to integrate and test various functionalities.
275+
## **10. Security Best Practices**
276+
277+
1. Use Strong Keys: Always use AES-256 for symmetric encryption and RSA-2048 for asymmetric encryption.
278+
2. Key Storage: Store keys securely using Android Keystore and iOS Keychain.
279+
3. Avoid Hardcoding Keys: Do not hardcode encryption keys directly in the app.
280+
281+
### 📚 **Encryption Mechanisms: Android (JCA) vs iOS (CryptoKit)**
282+
283+
| **Feature** | **Android (JCA)** | **iOS (CryptoKit)** |
284+
|--------------------------------|-------------------------------------|----------------------------------|
285+
| **Symmetric Encryption** | ✅ AES-256-GCM | ✅ AES-256-GCM |
286+
| **Asymmetric Encryption** | ✅ RSA-2048 | ✅ RSA-2048 |
287+
| **Key Derivation** | ✅ PBKDF2 | ✅ PBKDF2 / ✅ HKDF |
288+
| **Hashing** | ✅ SHA-256, ✅ SHA-512 | ✅ SHA-256, ✅ SHA-512 |
289+
| **Message Authentication** | ✅ HMAC-SHA256 | ✅ HMAC-SHA256 |
290+
| **Digital Signatures** | ✅ ECDSA | ✅ ECDSA (via CryptoKit) |
291+
| **Key Management** | ✅ Android Keystore | ✅ iOS Keychain |
292+
| **Initialization Vector (IV)** | ✅ SecureRandom (12/16 Bytes) | ✅ Randomized IV (12 Bytes) |
293+
| **Authentication Tag** | ✅ Built-in (GCM Mode) | ✅ Built-in (GCM Mode) |
294+
| **Error Handling** | ✅ Strong Validation | ✅ Strong Validation |
295+
| **Performance** | ⚡ Optimized for Android | ⚡ Optimized for iOS |
296+
| **Parallel Processing** | ✅ Supported in GCM | ✅ Supported in GCM |
297+
| **Cryptographic Library** | ✅ Java Cryptography (JCA) | ✅ CryptoKit |
274298

0 commit comments

Comments
 (0)