|
1 | 1 | # react-native-crypto-algorithm
|
2 | 2 |
|
3 |
| -Native Module using Kotlin & Swift for React-Native |
| 3 | +[](https://www.npmjs.com/package/react-native-encryption-algorithm) |
| 4 | +[](https://www.npmjs.com/package/react-native-encryption-algorithm) |
| 5 | +[](https://www.npmjs.com/package/react-native-encryption-algorithm) |
| 6 | +[](https://github.com/LamNguyen17/react-native-encryption-algorithm/blob/master/LICENSE) |
| 7 | +[](https://github.com/LamNguyen17) |
4 | 8 |
|
5 | 9 | ## Installation
|
| 10 | +```sh |
| 11 | +npm install react-native-encryption-algorithm |
| 12 | +``` |
| 13 | +or |
| 14 | +```sh |
| 15 | +yarn add react-native-encryption-algorithm |
| 16 | +``` |
| 17 | + |
| 18 | +### Installation (iOS) |
| 19 | + |
| 20 | +##### Using CocoaPods (React Native 0.60 and higher) |
6 | 21 |
|
7 | 22 | ```sh
|
8 |
| -npm install react-native-crypto-algorithm |
| 23 | +cd ios |
| 24 | +pod install |
| 25 | +``` |
| 26 | + |
| 27 | +##### Using React Native Link (React Native 0.59 and lower) |
| 28 | + |
| 29 | +Run `react-native link react-native-encryption-algorithm` after which you should be able to use this library on iOS. |
| 30 | + |
| 31 | +### Installation (Android) |
| 32 | + |
| 33 | +##### React Native 0.60 and higher |
| 34 | + |
| 35 | +- Linking is done automatically |
| 36 | + |
| 37 | +##### Using React Native Link (React Native 0.59 and lower) |
| 38 | + |
| 39 | +- In `android/settings.gradle` |
| 40 | + |
| 41 | +```gradle |
| 42 | +... |
| 43 | +include ':react-native-encryption-algorithm' |
| 44 | +project(':react-native-encryption-algorithm').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-encryption-algorithm/android') |
| 45 | +``` |
| 46 | + |
| 47 | +- In `android/app/build.gradle` |
| 48 | + |
| 49 | +```gradle |
| 50 | +... |
| 51 | +dependencies { |
| 52 | + ... |
| 53 | + compile project(':react-native-encryption-algorithm') |
| 54 | +} |
| 55 | +``` |
| 56 | +- register module (in MainApplication.kt) |
| 57 | + |
| 58 | +```kt |
| 59 | +...... |
| 60 | +import com.encryptionalgorithm.EncryptionAlgorithmPackage; |
| 61 | +...... |
| 62 | + |
| 63 | +override fun getPackages(): List<ReactPackage> = |
| 64 | + PackageList(this).packages.apply { |
| 65 | + add(EncryptionAlgorithmPackage()); |
| 66 | + } |
9 | 67 | ```
|
10 | 68 |
|
| 69 | +--- |
11 | 70 | ## Usage
|
| 71 | +### Methods |
| 72 | +#### 🚀 AES |
| 73 | +- Custom 'secretKey' -> maximum 32 characters |
| 74 | + . Custom 'ivKey' (optional) -> maximum 16 characters |
| 75 | +- 🍁 `encryptAES(value: string, secretKey: string, ivKey?: string)` |
| 76 | +- 🍁 `decryptAES(value: string, secretKey: string, ivKey?: string)` |
| 77 | +```js |
| 78 | +import Encryption from 'react-native-encryption-algorithm'; |
| 79 | + |
| 80 | +// Encrypt |
| 81 | +let encryptData = await Encryption.encryptAES('my message', 'my private key', 'my iv key(optional maximum 16 characters)'); |
12 | 82 |
|
| 83 | +// Decrypt |
| 84 | +let decryptData = await Encryption.decryptAES(encryptData, 'my private key', 'my iv key(optional maximum 16 characters)'); |
| 85 | +``` |
| 86 | + |
| 87 | +#### 🚀 SHA256 |
| 88 | +- 🍁 `hashSHA256(value: string)` |
| 89 | +```js |
| 90 | +import Encryption from 'react-native-encryption-algorithm'; |
| 91 | + |
| 92 | +// Hash SHA256 |
| 93 | +let hashData = await Encryption.hashSHA256('my hash data'); |
| 94 | +``` |
13 | 95 |
|
| 96 | +#### 🚀 RSA |
| 97 | +- 🍁 `genRSAKeyPair()` |
| 98 | +- 🍁 `encryptRSA(value: string, publicKey: string)` |
| 99 | +- 🍁 `decryptRSA(value: string, privateKey: string)` |
14 | 100 | ```js
|
15 |
| -import { multiply } from 'react-native-crypto-algorithm'; |
| 101 | +import Encryption from 'react-native-encryption-algorithm'; |
16 | 102 |
|
17 |
| -// ... |
| 103 | +// Generate RSA Key Pair |
| 104 | +let keyPair = await Encryption.genRSAKeyPair(); |
18 | 105 |
|
19 |
| -const result = await multiply(3, 7); |
| 106 | +// Encrypt RSA |
| 107 | +let encryptData = await Encryption.encryptRSA('my message', keyPair.publicKey); |
| 108 | + |
| 109 | +// Decrypt RSA |
| 110 | +let decryptData = await Encryption.decryptRSA(encryptData, keyPair.privateKey); |
20 | 111 | ```
|
21 | 112 |
|
| 113 | +#### 🚀 HMAC / HMAC_AES |
| 114 | +- 🍁 `genHmacSecretKey() -> use with all HMAC & HMAC_AES` |
| 115 | +- 🍁 `encryptHmacAes(value: string, publicKey: string) -> use only for HMAC_AES` |
| 116 | +- 🍁 `decryptHmacAes(value: string, privateKey: string) -> use only for HMAC_AES` |
| 117 | +- 🍁 `verifyHmac(value: string, privateKey: string) -> use only for HMAC` |
| 118 | +```js |
| 119 | +import Encryption from 'react-native-encryption-algorithm'; |
22 | 120 |
|
23 |
| -## Contributing |
| 121 | +// Generate HMAC & HMAC_AES |
| 122 | +let genHmacSecretKey = await Encryption.genHmacSecretKey(); |
24 | 123 |
|
25 |
| -See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow. |
| 124 | +// Encrypt HMAC_AES |
| 125 | +let encryptData = await Encryption.encryptHmacAes('my message', genHmacSecretKey); |
26 | 126 |
|
27 |
| -## License |
| 127 | +// Decrypt HMAC_AES |
| 128 | +let decryptData = await Encryption.decryptHmacAes(encryptData, genHmacSecretKey); |
28 | 129 |
|
29 |
| -MIT |
| 130 | +// VerifyHmac HMAC |
| 131 | +let verifyHmacData: boolean = await Encryption.verifyHmac('my message', genHmacSecretKey); |
| 132 | +``` |
30 | 133 |
|
31 | 134 | ---
|
32 |
| - |
33 |
| -Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob) |
| 135 | +## API |
| 136 | +### List of Algorithms |
| 137 | +- [x] ```AES(Advanced Encryption Standard)``` |
| 138 | +- [x] ```SHA-256 (Secure Hash Algorithm)``` |
| 139 | +- [x] ```RSA (Rivest-Shamir-Adleman)``` |
| 140 | +- [ ] ```ChaCha20``` |
| 141 | +- [ ] ```Blowfish``` |
| 142 | +- [x] ```HMAC (Hash-based Message Authentication Code)``` |
| 143 | +- [ ] ```PBKDF2 (Password-Based Key Derivation Function 2)``` |
| 144 | +- [ ] ```ECC (Elliptic Curve Cryptography)``` |
| 145 | +- [ ] ```Scrypt``` |
| 146 | +- [ ] ```XChaCha20-Poly1305``` |
| 147 | +--- |
| 148 | +## Author |
| 149 | + Forest Nguyen |
| 150 | + Email: devlamnt176@gmail.com |
| 151 | +--- |
| 152 | +## License |
| 153 | + MIT License |
| 154 | + Copyright (c) 2024 Forest Nguyen |
| 155 | +--- |
0 commit comments