Skip to content

Commit 1a63cb3

Browse files
committed
docs: update documentation
1 parent 25c41f0 commit 1a63cb3

1 file changed

Lines changed: 110 additions & 14 deletions

File tree

README.md

Lines changed: 110 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
# CryptoDriver
22

3-
CryptoDriver is a simple and easy-to-use encryption library for JavaScript applications. It provides a way to encrypt and decrypt data using the Advanced Encryption Standard (AES) algorithm with a user-provided key 🔑.
3+
The `CryptoDriver` is a simple and easy-to-use encryption class, manages cipher and decipher of data using the Advanced Encryption Standard (AES) `AES-256-GCM` algorithm with a user-provided key. This algorithm uses a 256-bit key and is considered one of the most secure symmetric encryption algorithms available.
4+
5+
## Table of Contents
6+
7+
- [Installation](##Installation)
8+
- [Importing](##Importing)
9+
- [Usage](##Usage)
10+
- [API](##API)
11+
- [CryptoDriver(key)](###CryptoDriver(key))
12+
- [CryptoDriver#encrypt(data)](###CryptoDriver#encrypt(data))
13+
- [CryptoDriver#decrypt(encrypted)](###CryptoDriver#decrypt(encrypted))
14+
- [Security Considerations](##Security-Considerations)
15+
- [Contributing](##Contributing)
16+
- [License](##License)
417

518
## Installation
619

@@ -22,30 +35,113 @@ import CryptoDriver from 'crypto-driver';
2235
const CryptoDriver = require('crypto-driver');
2336
```
2437

25-
## Overview
26-
27-
### Create instance
38+
## Usage
2839

29-
Then, create a new instance of the CryptoDriver class with your encryption key:
40+
The `CryptoDriver` module is a class that needs to be instantiated with a key before it can be used. Once instantiated, you can use the `encrypt()` and `decrypt()` methods to encrypt and decrypt data.
3041

3142
```js
32-
const key = 'e79b44ab0dbb6934385921e95aaaf67fa88e61c0a0ca44f841da3729604ef62a145be70de13ed1';
33-
const cryptoDriver = new CryptoDriver(key);
43+
const CryptoDriver = require('crypto-driver');
44+
45+
const key = 'd6F3Efeqd6F3Efeqd6F3Efeqd6F3Efeq';
46+
const crypto = new CryptoDriver(key);
47+
48+
const data = 'This is my secret message';
49+
50+
// Encrypt the original data
51+
const encrypted = crypto.encrypt(data);
52+
53+
// Decrypt the encrypted data
54+
const decrypted = crypto.decrypt(encrypted);
55+
56+
console.log(data); // This is my secret message
57+
console.log(encrypted); // 2fV+Hd1vN6rByYjKsNixNl2eDvUJziG/6kKj8zJb+zk=BvLrZrTjTxbV6QAAAAA
58+
console.log(decrypted ); // This is my secret message
59+
3460
```
3561

36-
### Use methods
62+
## API
3763

38-
You can then use the encrypt and decrypt methods to encrypt and decrypt data, respectively:
64+
### `CryptoDriver(key)`
65+
66+
Creates an instance of the CryptoDriver class.
67+
68+
Arguments
69+
70+
| Name | Type | Description |
71+
|-------|----------|------------------------------------------------------------------------------------|
72+
| `key` | `string` | The `key` used for encryption and decryption. Must be a `string` of 32 characters. |
73+
74+
Throws
75+
76+
| Type | Description |
77+
|------------------|--------------------------------------------------------|
78+
| `ReferenceError` | If the `key` value is `undefined`. |
79+
| `TypeError` | If the `key` value is not a `string`. |
80+
| `RangeError` | If the length of the `key` value is not 32 characters. |
81+
82+
Example
3983

4084
```js
41-
const plaintext = 'Hello, world!';
42-
const ciphertext = cryptoDriver.encrypt(plaintext);
43-
const decryptedText = cryptoDriver.decrypt(ciphertext);
44-
console.log(decryptedText); // Output: Hello, world!
85+
const CryptoDriver = require('crypto-driver');
86+
87+
const key = 'd6F3Efeqd6F3Efeqd6F3Efeqd6F3Efeq';
88+
const crypto = new CryptoDriver(key);
89+
```
90+
91+
### `CryptoDriver#encrypt(data)`
4592

93+
Encrypts the specified data using the AES-256-GCM encryption algorithm.
94+
95+
Arguments
96+
97+
| Name | Type | Description |
98+
|--------|----------|-----------------------------------------------|
99+
| `data` | `string` | The data to be encrypted. Must be a `string`. |
100+
101+
Returns
102+
103+
A `string` representing the encrypted data.
104+
105+
Throws
106+
107+
| Type | Description |
108+
|------------------|----------------------------------------|
109+
| `ReferenceError` | If the `data` value is `undefined`. |
110+
| `TypeError` | If the `data` value is not a `string`. |
111+
112+
Example
113+
114+
```js
115+
const encrypted = crypto.encrypt('This is my secret message');
46116
```
47117

48-
See [documentation](https://github.com/vgbr-dev/crypto-driver/wiki#cryptodriver) for more details.
118+
### `CryptoDriver#decrypt(encrypted)`
119+
120+
Decrypts the specified encrypted data using the AES-256-GCM encryption algorithm.
121+
122+
Arguments
123+
124+
| Name | Type | Description |
125+
|-------------|----------|---------------------------------------------------------|
126+
| `encrypted` | `string` | The encrypted data to be decrypted. Must be a `string`. |
127+
128+
Returns
129+
130+
A `string` representing the decrypted data.
131+
132+
Throws
133+
134+
| Type | Description |
135+
|------------------|---------------------------------------------|
136+
| `ReferenceError` | If the `encrypted` value is `undefined`. |
137+
| `TypeError` | If the `encrypted` value is not a `string`. |
138+
139+
Example
140+
141+
```js
142+
const encrypted = crypto.encrypt('This is my secret message');
143+
const decrypted = crypto.decrypt(encrypted);
144+
```
49145

50146
## Security Considerations
51147

0 commit comments

Comments
 (0)