mirror of
https://github.com/cupcakearmy/occulto.git
synced 2024-12-22 10:46:30 +00:00
Update README.md
This commit is contained in:
parent
c1e4f4b1aa
commit
bb913e30fb
120
README.md
120
README.md
@ -28,9 +28,9 @@ const decrypted = RSA.decrypt(encrypted, 'myPass')
|
|||||||
|
|
||||||
## RSA
|
## RSA
|
||||||
|
|
||||||
#### `RSA.gen(bits:? number)`
|
#### `RSA.gen(size: number = 2 ** 12)`
|
||||||
|
|
||||||
- bits: [optional, default=4096] Size of the RSA key
|
- size: [optional, default=4096] Size of the RSA key
|
||||||
|
|
||||||
###### Examples
|
###### Examples
|
||||||
|
|
||||||
@ -39,105 +39,59 @@ const pair = await RSA.gen() // 4096-Bit
|
|||||||
const smallPair = await RSA.gen(2**10) // 1024-Bit
|
const smallPair = await RSA.gen(2**10) // 1024-Bit
|
||||||
```
|
```
|
||||||
|
|
||||||
#### `.add(amount, interval)`
|
#### `RSA.encrypt(data: string, key: PublicKey)`
|
||||||
|
|
||||||
Adds a specified amount to an existing duration
|
Encrypt message with public key
|
||||||
|
|
||||||
###### Example
|
###### Example
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const a = new Duration(1, 'day')
|
const pair = await RSA.gen()
|
||||||
a.add(12, 'hours')
|
const encrypted = RSA.encrypt('some text', pair.pub)
|
||||||
a.asHour() // 36
|
|
||||||
```
|
```
|
||||||
|
|
||||||
#### `.subtract(amount, interval)`
|
#### `RSA.decrypt(data: string, key: PrivateKey)`
|
||||||
|
|
||||||
Subtracts a specified amount to an existing duration
|
Decrypts a message encrypted with `RSA.encrypt()` with the private key
|
||||||
|
|
||||||
###### Example
|
###### Example
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const a = new Duration(1, 'day')
|
const pair = await RSA.gen()
|
||||||
a.subtract(12, 'hours')
|
const encrypted = RSA.encrypt('some text', pair.pub)
|
||||||
a.asHour() // 12
|
const decrypted = RSA.decrypt(encrypted, pair.prv)
|
||||||
```
|
```
|
||||||
|
|
||||||
#### Getters
|
## AES
|
||||||
|
|
||||||
Gets the amount of time interval, not the total time
|
### `AES.Ciphers`
|
||||||
|
|
||||||
- `.milliseconds()`
|
Available ciphers
|
||||||
- `.seconds()`
|
|
||||||
- `.minutes()`
|
- `Ciphers.AES_256_GCM`
|
||||||
- `.hours()`
|
- `Ciphers.AES_192_GCM`
|
||||||
- `.days()`
|
- `Ciphers.AES_128_GCM`
|
||||||
- `.weeks()`
|
|
||||||
- `.years()`
|
#### `AES.encrypt(data: string, key: string, type: Ciphers = Ciphers.AES_256_GCM)`
|
||||||
|
|
||||||
|
Encrypts a string.
|
||||||
|
Defaults to `Ciphers.AES_256_GCM`
|
||||||
|
|
||||||
|
###### Examples
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
const encrypted = AES.encrypt('some string' , 'myPass')
|
||||||
|
|
||||||
|
const e = AES.encrypt('some string' , 'myPass', Ciphers.AES_128_GCM)
|
||||||
|
```
|
||||||
|
|
||||||
|
#### `RSA.decrypt(e: string, key: string)`
|
||||||
|
|
||||||
|
Decrypt data encrypted by `AES.encrypt()`
|
||||||
|
|
||||||
###### Example
|
###### Example
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const a = new Duration(1, 'day')
|
const encrypted = AES.encrypt('some string' , 'myPass')
|
||||||
a.days() // 1
|
const decrypted = AES.decrypt(encrypted , 'myPass')
|
||||||
a.add(5, 'minutes')
|
|
||||||
a.days() // 1
|
|
||||||
a.add(1, 'year')
|
|
||||||
a.days() // 1
|
|
||||||
a.add(24, 'hours')
|
|
||||||
a.days() // 2
|
|
||||||
```
|
|
||||||
|
|
||||||
#### As interval
|
|
||||||
|
|
||||||
Calculates the time duration as a time interval.
|
|
||||||
|
|
||||||
- `.asMilliseconds()`
|
|
||||||
- `.asSeconds()`
|
|
||||||
- `.asMinutes()`
|
|
||||||
- `.asHours()`
|
|
||||||
- `.asDays()`
|
|
||||||
- `.asWeeks()`
|
|
||||||
- `.asYears()`
|
|
||||||
|
|
||||||
###### Example
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
const a = new Duration(1, 'day')
|
|
||||||
a.asHours() // 24
|
|
||||||
```
|
|
||||||
|
|
||||||
#### `.humanize()`
|
|
||||||
|
|
||||||
This functions takes a duration and tries to make a human readable version out of it.
|
|
||||||
|
|
||||||
###### Example
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
const a = new Duration(4, 'seconds')
|
|
||||||
a.humanize() // 'a moment'
|
|
||||||
a.add(5, 'minutes')
|
|
||||||
a.humanize() // 'a few minutes'
|
|
||||||
```
|
|
||||||
|
|
||||||
##### Own rules / i18n
|
|
||||||
|
|
||||||
If you want to pass a different humanize function you can.
|
|
||||||
The order of the array is important. The first match will return, like in a standard server router. The first argument is a function that takes the duration and returns a boolean. The second takes also matched duration and returns a string for the user.
|
|
||||||
|
|
||||||
###### Example
|
|
||||||
|
|
||||||
```javascript
|
|
||||||
const humanizer = [
|
|
||||||
[d => d.days() > 1, d => `${d.days()} days`],
|
|
||||||
[d => d.days() > 0, d => `1 day`],
|
|
||||||
[() => true, () => 'catch all, below 1 day'],
|
|
||||||
]
|
|
||||||
|
|
||||||
const a = new Duration(2, 'days')
|
|
||||||
a.humanize(humanizer) // '2 days'
|
|
||||||
a.subtract(1, 'day')
|
|
||||||
a.humanize(humanizer) // '1 day'
|
|
||||||
a.subtract(12, 'hours')
|
|
||||||
a.humanize(humanizer) // 'catch all, below 1 day'
|
|
||||||
```
|
```
|
||||||
|
Loading…
Reference in New Issue
Block a user