occulto/README.md

98 lines
1.8 KiB
Markdown
Raw Normal View History

2019-03-30 20:50:04 +01:00
# occulto 🔒
High leven wrapper around [forge](https://github.com/digitalbazaar/forge).
**Typescript typings included**
## Quickstart 🚀
###### Install
```
npm i occulto
```
```javascript
// Whatever import you prefer
// const { RSA } = require('occulto')
import { RSA } from 'occulto'
const pair = await RSA.gen()
const encrypted = RSA.encrypt('some string', 'myPass')
const decrypted = RSA.decrypt(encrypted, 'myPass')
```
### Reference 📒
## RSA
2019-03-30 21:01:12 +01:00
#### `RSA.gen(size: number = 2 ** 12)`
2019-03-30 20:50:04 +01:00
2019-03-30 21:01:12 +01:00
- size: [optional, default=4096] Size of the RSA key
2019-03-30 20:50:04 +01:00
###### Examples
```javascript
const pair = await RSA.gen() // 4096-Bit
const smallPair = await RSA.gen(2**10) // 1024-Bit
```
2019-03-30 21:01:12 +01:00
#### `RSA.encrypt(data: string, key: PublicKey)`
2019-03-30 20:50:04 +01:00
2019-03-30 21:01:12 +01:00
Encrypt message with public key
2019-03-30 20:50:04 +01:00
###### Example
```javascript
2019-03-30 21:01:12 +01:00
const pair = await RSA.gen()
const encrypted = RSA.encrypt('some text', pair.pub)
2019-03-30 20:50:04 +01:00
```
2019-03-30 21:01:12 +01:00
#### `RSA.decrypt(data: string, key: PrivateKey)`
2019-03-30 20:50:04 +01:00
2019-03-30 21:01:12 +01:00
Decrypts a message encrypted with `RSA.encrypt()` with the private key
2019-03-30 20:50:04 +01:00
###### Example
```javascript
2019-03-30 21:01:12 +01:00
const pair = await RSA.gen()
const encrypted = RSA.encrypt('some text', pair.pub)
const decrypted = RSA.decrypt(encrypted, pair.prv)
2019-03-30 20:50:04 +01:00
```
2019-03-30 21:01:12 +01:00
## AES
2019-03-30 20:50:04 +01:00
2019-03-30 21:01:12 +01:00
### `AES.Ciphers`
2019-03-30 20:50:04 +01:00
2019-03-30 21:01:12 +01:00
Available ciphers
2019-03-30 20:50:04 +01:00
2019-03-30 21:01:12 +01:00
- `Ciphers.AES_256_GCM`
- `Ciphers.AES_192_GCM`
- `Ciphers.AES_128_GCM`
2019-03-30 20:50:04 +01:00
2019-03-30 21:01:12 +01:00
#### `AES.encrypt(data: string, key: string, type: Ciphers = Ciphers.AES_256_GCM)`
2019-03-30 20:50:04 +01:00
2019-03-30 21:01:12 +01:00
Encrypts a string.
Defaults to `Ciphers.AES_256_GCM`
2019-03-30 20:50:04 +01:00
2019-03-30 21:01:12 +01:00
###### Examples
2019-03-30 20:50:04 +01:00
```javascript
2019-03-30 21:01:12 +01:00
const encrypted = AES.encrypt('some string' , 'myPass')
2019-03-30 20:50:04 +01:00
2019-03-30 21:01:12 +01:00
const e = AES.encrypt('some string' , 'myPass', Ciphers.AES_128_GCM)
2019-03-30 20:50:04 +01:00
```
2019-03-30 21:01:12 +01:00
#### `RSA.decrypt(e: string, key: string)`
2019-03-30 20:50:04 +01:00
2019-03-30 21:01:12 +01:00
Decrypt data encrypted by `AES.encrypt()`
2019-03-30 20:50:04 +01:00
###### Example
```javascript
2019-03-30 21:01:12 +01:00
const encrypted = AES.encrypt('some string' , 'myPass')
const decrypted = AES.decrypt(encrypted , 'myPass')
2019-03-30 20:50:04 +01:00
```