occulto/README.md

81 lines
1.9 KiB
Markdown
Raw Normal View History

2019-03-30 20:50:04 +01:00
# occulto 🔒
> Occulto <kbd>/okˈkul.to/</kbd>
>
> _hidden, concealed. secret._
2019-07-07 21:20:42 +02:00
![version badge](https://badgen.net/npm/v/occulto)
![downloads badge](https://badgen.net/npm/dt/occulto)
![dependency count](https://badgen.net/bundlephobia/dependency-count/occulto)
![minzip size badge](https://badgen.net/bundlephobia/minzip/occulto)
![types badge](https://badgen.net/npm/types/occulto)
2019-03-30 20:50:04 +01:00
Isomorphic encryption library that works both in the browser and node with _no dependencies_ and written in Typescript.
2019-03-30 20:50:04 +01:00
[**📒 API Documentation 📒**](https://occulto.pages.dev)
2019-07-07 21:47:57 +02:00
2019-03-30 20:50:04 +01:00
## Quickstart 🚀
2019-07-10 10:35:00 +02:00
###### Requirements
- Node >= 16 required
2019-07-10 10:35:00 +02:00
2019-03-30 20:50:04 +01:00
###### Install
```
2019-07-10 10:35:42 +02:00
npm i occulto
2019-03-30 20:50:04 +01:00
```
## Examples
2019-03-30 20:50:04 +01:00
### [RSA](https://occulto.pages.dev/classes/RSA)
2019-03-30 20:50:04 +01:00
2019-07-07 21:44:18 +02:00
```typescript
2019-07-07 21:48:49 +02:00
import { RSA } from 'occulto'
2023-01-14 18:49:31 +01:00
const pair = await RSA.generateKeyPair(2 ** 11)
const bytes = Bytes.encode(message)
const encrypted = await RSA.encrypt(bytes, pair.public)
const decrypted = await RSA.decrypt(encrypted, pair.private)
2019-03-30 20:50:04 +01:00
```
### [AES](https://occulto.pages.dev/classes/AES)
2019-07-07 21:47:57 +02:00
[Available Modes](https://occulto.pages.dev/enums/Modes)
2019-03-30 20:50:04 +01:00
2023-01-14 18:49:31 +01:00
There is an _easy_ API, that will take care of everything for you.
```typescript
import { AES } from 'occulto'
const password = 'foobar'
const message = 'this is a secret'
2019-03-30 20:50:04 +01:00
2023-01-14 18:49:31 +01:00
const encrypted = await AES.encryptEasy(message, password)
const decrypted = await AES.decryptEasy(encrypted, password)
```
The low level API is also exposed for advanced usages.
```typescript
import { AES } from 'occulto'
const message = 'this is a secret'
const key = await AES.generateKey()
const data = Bytes.encode(message)
const ciphertext = await AES.encrypt(data, key)
const plaintext = await AES.decrypt(ciphertext, key)
2019-03-30 20:50:04 +01:00
```
### [Hash](https://occulto.pages.dev/classes/Hash)
2019-07-07 21:46:09 +02:00
[Available hashes](https://occulto.pages.dev/enums/Hashes)
2019-07-07 21:46:09 +02:00
2019-07-07 21:44:18 +02:00
```typescript
2023-01-14 18:49:31 +01:00
import { Hash, Hashes } from 'occulto'
2019-07-07 21:20:42 +02:00
2023-01-14 18:49:31 +01:00
const hashed = await Hash.hash('Some value', Hashes.SHA_512)
2019-03-30 20:50:04 +01:00
```