Skip to content

update readme #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 23 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# react-native-crypto-algorithm

[![](https://img.shields.io/badge/yarn-v1.0.0-blue)](https://www.npmjs.com/package/react-native-encryption-algorithm)
[![](https://img.shields.io/badge/yarn-v1.0.1-blue)](https://www.npmjs.com/package/react-native-encryption-algorithm)
[![](https://img.shields.io/badge/native_language-Kotlin_&_Swift-green)](https://www.npmjs.com/package/react-native-encryption-algorithm)
[![](https://img.shields.io/badge/size-72.7_kB-red)](https://www.npmjs.com/package/react-native-encryption-algorithm)
[![](https://img.shields.io/badge/license-MIT-8A2BE2)](https://github.com/LamNguyen17/react-native-encryption-algorithm/blob/master/LICENSE)
[![](https://img.shields.io/badge/author-Forest_Nguyen-f59642)](https://github.com/LamNguyen17)

## Installation
```sh
npm install react-native-encryption-algorithm
npm install react-native-crypto-algorithm
```
or
```sh
yarn add react-native-encryption-algorithm
yarn add react-native-crypto-algorithm
```

### Installation (iOS)
Expand All @@ -26,7 +26,7 @@ pod install

##### Using React Native Link (React Native 0.59 and lower)

Run `react-native link react-native-encryption-algorithm` after which you should be able to use this library on iOS.
Run `react-native link react-native-crypto-algorithm` after which you should be able to use this library on iOS.

### Installation (Android)

Expand All @@ -40,8 +40,8 @@ Run `react-native link react-native-encryption-algorithm` after which you should

```gradle
...
include ':react-native-encryption-algorithm'
project(':react-native-encryption-algorithm').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-encryption-algorithm/android')
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`
Expand All @@ -50,19 +50,19 @@ project(':react-native-encryption-algorithm').projectDir = new File(rootProject.
...
dependencies {
...
compile project(':react-native-encryption-algorithm')
compile project(':react-native-crypto-algorithm')
}
```
- register module (in MainApplication.kt)

```kt
......
import com.encryptionalgorithm.EncryptionAlgorithmPackage;
import com.cryptoalgorithm.CryptoAlgorithmPackage;
......

override fun getPackages(): List<ReactPackage> =
PackageList(this).packages.apply {
add(EncryptionAlgorithmPackage());
add(CryptoAlgorithmPackage());
}
```

Expand All @@ -75,39 +75,39 @@ override fun getPackages(): List<ReactPackage> =
- 🍁 `encryptAES(value: string, secretKey: string, ivKey?: string)`
- 🍁 `decryptAES(value: string, secretKey: string, ivKey?: string)`
```js
import Encryption from 'react-native-encryption-algorithm';
import Crypto from 'react-native-crypto-algorithm';

// Encrypt
let encryptData = await Encryption.encryptAES('my message', 'my private key', 'my iv key(optional maximum 16 characters)');
let encryptData = await Crypto.encryptAES('my message', 'my private key', 'my iv key(optional maximum 16 characters)');

// Decrypt
let decryptData = await Encryption.decryptAES(encryptData, 'my private key', 'my iv key(optional maximum 16 characters)');
let decryptData = await Crypto.decryptAES(encryptData, 'my private key', 'my iv key(optional maximum 16 characters)');
```

#### 🚀 SHA256
- 🍁 `hashSHA256(value: string)`
```js
import Encryption from 'react-native-encryption-algorithm';
import Crypto from 'react-native-crypto-algorithm';

// Hash SHA256
let hashData = await Encryption.hashSHA256('my hash data');
let hashData = await Crypto.hashSHA256('my hash data');
```

#### 🚀 RSA
- 🍁 `genRSAKeyPair()`
- 🍁 `encryptRSA(value: string, publicKey: string)`
- 🍁 `decryptRSA(value: string, privateKey: string)`
```js
import Encryption from 'react-native-encryption-algorithm';
import Crypto from 'react-native-crypto-algorithm';

// Generate RSA Key Pair
let keyPair = await Encryption.genRSAKeyPair();
let keyPair = await Crypto.genRSAKeyPair();

// Encrypt RSA
let encryptData = await Encryption.encryptRSA('my message', keyPair.publicKey);
let encryptData = await Crypto.encryptRSA('my message', keyPair.publicKey);

// Decrypt RSA
let decryptData = await Encryption.decryptRSA(encryptData, keyPair.privateKey);
let decryptData = await Crypto.decryptRSA(encryptData, keyPair.privateKey);
```

#### 🚀 HMAC / HMAC_AES
Expand All @@ -116,19 +116,19 @@ let decryptData = await Encryption.decryptRSA(encryptData, keyPair.privateKey);
- 🍁 `decryptHmacAes(value: string, privateKey: string) -> use only for HMAC_AES`
- 🍁 `verifyHmac(value: string, privateKey: string) -> use only for HMAC`
```js
import Encryption from 'react-native-encryption-algorithm';
import Crypto from 'react-native-crypto-algorithm';

// Generate HMAC & HMAC_AES
let genHmacSecretKey = await Encryption.genHmacSecretKey();
let genHmacSecretKey = await Crypto.genHmacSecretKey();

// Encrypt HMAC_AES
let encryptData = await Encryption.encryptHmacAes('my message', genHmacSecretKey);
let encryptData = await Crypto.encryptHmacAes('my message', genHmacSecretKey);

// Decrypt HMAC_AES
let decryptData = await Encryption.decryptHmacAes(encryptData, genHmacSecretKey);
let decryptData = await Crypto.decryptHmacAes(encryptData, genHmacSecretKey);

// VerifyHmac HMAC
let verifyHmacData: boolean = await Encryption.verifyHmac('my message', genHmacSecretKey);
let verifyHmacData: boolean = await Crypto.verifyHmac('my message', genHmacSecretKey);
```

---
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-crypto-algorithm",
"version": "1.0.0",
"version": "1.0.1",
"description": "Native Module using Kotlin & Swift for React-Native",
"source": "./src/index.tsx",
"main": "./lib/commonjs/index.js",
Expand Down
4 changes: 4 additions & 0 deletions src/CryptoAlgorithm.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ interface CryptoAlgorithmInterface {
genRSAKeyPair(): Promise<any>;
encryptRSA(value: string, publicKey: string): Promise<string|null>;
decryptRSA(value: string, privateKey: string): Promise<string|null>;
genHmacSecretKey(): Promise<null>;
encryptHmacAes(value: string, privateKey: string): Promise<string|null>;
decryptHmacAes(value: string, privateKey: string): Promise<string|null>;
verifyHmac(value: string, privateKey: string): Promise<string|null>;
}

export default CryptoAlgorithm as CryptoAlgorithmInterface;
2 changes: 1 addition & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { NativeModules } from 'react-native';

const CryptoAlgorithmNative = NativeModules.CryptoAlgorithm;

export default class Encryption {
export default class Crypto {
static hashSHA256 = (value: string) => {
return CryptoAlgorithmNative.hashSHA256(value);
};
Expand Down