Update README.md

This commit is contained in:
Nicco 2019-03-30 21:01:12 +01:00 committed by GitHub
parent c1e4f4b1aa
commit bb913e30fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

120
README.md
View File

@ -28,9 +28,9 @@ const decrypted = RSA.decrypt(encrypted, 'myPass')
## 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
@ -39,105 +39,59 @@ const pair = await RSA.gen() // 4096-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
```javascript
const a = new Duration(1, 'day')
a.add(12, 'hours')
a.asHour() // 36
const pair = await RSA.gen()
const encrypted = RSA.encrypt('some text', pair.pub)
```
#### `.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
```javascript
const a = new Duration(1, 'day')
a.subtract(12, 'hours')
a.asHour() // 12
const pair = await RSA.gen()
const encrypted = RSA.encrypt('some text', pair.pub)
const decrypted = RSA.decrypt(encrypted, pair.prv)
```
#### Getters
## AES
Gets the amount of time interval, not the total time
### `AES.Ciphers`
- `.milliseconds()`
- `.seconds()`
- `.minutes()`
- `.hours()`
- `.days()`
- `.weeks()`
- `.years()`
Available ciphers
- `Ciphers.AES_256_GCM`
- `Ciphers.AES_192_GCM`
- `Ciphers.AES_128_GCM`
#### `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
```javascript
const a = new Duration(1, 'day')
a.days() // 1
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'
const encrypted = AES.encrypt('some string' , 'myPass')
const decrypted = AES.decrypt(encrypted , 'myPass')
```