mirror of
https://github.com/cupcakearmy/occulto.git
synced 2025-01-03 00:56:28 +00:00
added utils and hashing
This commit is contained in:
parent
df89829327
commit
6096036063
18
src/Hash.ts
Normal file
18
src/Hash.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import { createHash } from 'crypto'
|
||||||
|
|
||||||
|
enum Hashes {
|
||||||
|
MD5 = 'md5',
|
||||||
|
SHA1_1 = 'sha1',
|
||||||
|
SHA1_256 = 'sha256',
|
||||||
|
SHA1_512 = 'sha512',
|
||||||
|
SHA3_256 = 'sha3-256',
|
||||||
|
SHA3_384 = 'sha3-384',
|
||||||
|
SHA3_512 = 'sha3-512',
|
||||||
|
}
|
||||||
|
|
||||||
|
export default class Hash {
|
||||||
|
|
||||||
|
static Hashes = Hashes
|
||||||
|
|
||||||
|
static digest = (s: string, type: Hashes = Hashes.SHA3_256): string => createHash(type).update(s).digest().toString('hex')
|
||||||
|
}
|
16
src/Util.ts
16
src/Util.ts
@ -1,4 +1,20 @@
|
|||||||
|
import { randomBytes } from 'crypto'
|
||||||
|
|
||||||
export class Base64 {
|
export class Base64 {
|
||||||
static encode = (s: string): string => Buffer.from(s).toString('base64')
|
static encode = (s: string): string => Buffer.from(s).toString('base64')
|
||||||
static decode = (s: string): string => Buffer.from(s, 'base64').toString()
|
static decode = (s: string): string => Buffer.from(s, 'base64').toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function Rand(length: number, string: false): Buffer
|
||||||
|
function Rand(length: number, string: true): string
|
||||||
|
function Rand(length: number, string: boolean = false): Buffer | string {
|
||||||
|
const r = randomBytes(length)
|
||||||
|
return string
|
||||||
|
? r.toString('ascii')
|
||||||
|
: r
|
||||||
|
}
|
||||||
|
|
||||||
|
export default {
|
||||||
|
Rand
|
||||||
}
|
}
|
16
src/index.ts
16
src/index.ts
@ -1,14 +1,20 @@
|
|||||||
import RSA_Internal from './RSA'
|
import H from './Hash'
|
||||||
import Symmetric_Internal from './Symmetric'
|
import R from './RSA'
|
||||||
|
import S from './Symmetric'
|
||||||
|
import U from './Util'
|
||||||
|
|
||||||
export const RSA = RSA_Internal
|
export const RSA = R
|
||||||
export const Symmetric = Symmetric_Internal
|
export const Symmetric = S
|
||||||
|
export const Hash = H
|
||||||
|
export const Util = U
|
||||||
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
RSA,
|
RSA,
|
||||||
Symmetric,
|
Symmetric,
|
||||||
|
Hash,
|
||||||
|
Util,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Require node 11
|
// Require node 11
|
||||||
if (parseInt(process.versions.node.split('.')[0]) < 10) throw new Error('Node 10 or higher is required')
|
if (parseInt(process.versions.node.split('.')[0]) < 11) throw new Error('Node 11 or higher is required')
|
Loading…
Reference in New Issue
Block a user