https://github.com/lamnguyen17/react-native-crypto-algorithm
Native Module using Kotlin & Swift for React-Native
https://github.com/lamnguyen17/react-native-crypto-algorithm
corountines-flows cryptoswift kotlin-android kotlin-coroutines native-modules react-native reactive-programming rxswift swift-ios
Last synced: 6 months ago
JSON representation
Native Module using Kotlin & Swift for React-Native
- Host: GitHub
- URL: https://github.com/lamnguyen17/react-native-crypto-algorithm
- Owner: LamNguyen17
- License: mit
- Created: 2024-10-10T09:29:11.000Z (8 months ago)
- Default Branch: master
- Last Pushed: 2024-10-18T08:40:19.000Z (7 months ago)
- Last Synced: 2024-10-19T13:20:54.877Z (7 months ago)
- Topics: corountines-flows, cryptoswift, kotlin-android, kotlin-coroutines, native-modules, react-native, reactive-programming, rxswift, swift-ios
- Language: Swift
- Homepage:
- Size: 1.4 MB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# react-native-crypto-algorithm
[](https://www.npmjs.com/package/react-native-crypto-algorithm)
[](https://www.npmjs.com/package/react-native-crypto-algorithm)
[](https://www.npmjs.com/package/react-native-crypto-algorithm)
[](https://github.com/LamNguyen17/react-native-crypto-algorithm/blob/master/LICENSE)
[](https://github.com/LamNguyen17)## Installation
```sh
npm install react-native-crypto-algorithm
```
or
```sh
yarn add react-native-crypto-algorithm
```### Installation (iOS)
##### Using CocoaPods (React Native 0.60 and higher)
```sh
cd ios
pod install
```##### Using React Native Link (React Native 0.59 and lower)
Run `react-native link react-native-crypto-algorithm` after which you should be able to use this library on iOS.
### Installation (Android)
##### React Native 0.60 and higher
- Linking is done automatically
##### Using React Native Link (React Native 0.59 and lower)
- In `android/settings.gradle`
```gradle
...
include ':react-native-crypto-algorithm'
project(':react-native-crypto-algorithm').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-crypto-algorithm/android')
```- In `android/app/build.gradle`
```gradle
...
dependencies {
...
compile project(':react-native-crypto-algorithm')
}
```
- register module (in MainApplication.kt)```kt
......
import com.cryptoalgorithm.CryptoAlgorithmPackage;
......override fun getPackages(): List =
PackageList(this).packages.apply {
add(CryptoAlgorithmPackage());
}
```---
## Usage
### Methods
#### 🚀 AES
- Custom 'secretKey' -> maximum 32 characters
. Custom 'ivKey' (optional) -> maximum 16 characters
- 🍁 `encryptAES(value: string, secretKey: string, ivKey?: string)`
- 🍁 `decryptAES(value: string, secretKey: string, ivKey?: string)`
```js
import Crypto from 'react-native-crypto-algorithm';// Encrypt
let encryptData = await Crypto.encryptAES('my message', 'my private key', 'my iv key(optional maximum 16 characters)');// Decrypt
let decryptData = await Crypto.decryptAES(encryptData, 'my private key', 'my iv key(optional maximum 16 characters)');
```#### 🚀 SHA256
- 🍁 `hashSHA256(value: string)`
```js
import Crypto from 'react-native-crypto-algorithm';// Hash SHA256
let hashData = await Crypto.hashSHA256('my hash data');
```#### 🚀 RSA
- 🍁 `genRSAKeyPair()`
- 🍁 `encryptRSA(value: string, publicKey: string)`
- 🍁 `decryptRSA(value: string, privateKey: string)`
```js
import Crypto from 'react-native-crypto-algorithm';// Generate RSA Key Pair
let keyPair = await Crypto.genRSAKeyPair();// Encrypt RSA
let encryptData = await Crypto.encryptRSA('my message', keyPair.publicKey);// Decrypt RSA
let decryptData = await Crypto.decryptRSA(encryptData, keyPair.privateKey);
```#### 🚀 HMAC / HMAC_AES
- 🍁 `genHmacSecretKey() -> use with all HMAC & HMAC_AES`
- 🍁 `encryptHmacAes(value: string, publicKey: string) -> use only for HMAC_AES`
- 🍁 `decryptHmacAes(value: string, privateKey: string) -> use only for HMAC_AES`
- 🍁 `verifyHmac(value: string, privateKey: string) -> use only for HMAC`
```js
import Crypto from 'react-native-crypto-algorithm';// Generate HMAC & HMAC_AES
let genHmacSecretKey = await Crypto.genHmacSecretKey();// Encrypt HMAC_AES
let encryptData = await Crypto.encryptHmacAes('my message', genHmacSecretKey);// Decrypt HMAC_AES
let decryptData = await Crypto.decryptHmacAes(encryptData, genHmacSecretKey);// VerifyHmac HMAC
let verifyHmacData: boolean = await Crypto.verifyHmac('my message', genHmacSecretKey);
```---
## API
### List of Algorithms
- [x] ```AES(Advanced Encryption Standard)```
- [x] ```SHA-256 (Secure Hash Algorithm)```
- [x] ```RSA (Rivest-Shamir-Adleman)```
- [ ] ```ChaCha20```
- [ ] ```Blowfish```
- [x] ```HMAC (Hash-based Message Authentication Code)```
- [ ] ```PBKDF2 (Password-Based Key Derivation Function 2)```
- [ ] ```ECC (Elliptic Curve Cryptography)```
- [ ] ```Scrypt```
- [ ] ```XChaCha20-Poly1305```
---
## Author
Forest Nguyen
Email: [email protected]
---
## License
MIT License
Copyright (c) 2024 Forest Nguyen
---