silvie
Version:
Typescript Back-end Framework
59 lines (58 loc) • 1.89 kB
TypeScript
/// <reference types="node" />
import { THashDigest, TCipherDigest, TData, THashMethod, TCipherMethod } from "./types";
export default class Crypt {
/**
* Uses bcrypt to make hash from a plain value
* @param plain
*/
static make(plain: string): string;
/**
* Uses bcrypt to compare a plain value against a hashed value
* @param plain
* @param hashed
*/
static check(plain: string, hashed: string): boolean;
/**
* Hashes the specified data
* @param data Data to be hashed
* @param algorithm Hashing algorithm (defaults to sha256)
* @param digest returning digest type (defaults to hex)
*/
static hash(data: TData, algorithm?: THashMethod, digest?: THashDigest): string;
/**
* Generate random IV
* @param length
*/
static generateIV(length?: number): Buffer;
/**
* Generate random Key
* @param length
*/
static generateKey(length?: number): Buffer;
/**
* Generate a buffer with random bytes
* @param length
*/
static randomBytes(length: any): Buffer;
/**
* Encrypt a data with a key and iv
* @param data
* @param key Encryption key
* @param algorithm Encryption algorithm
* @param digest Output digest type
* @param IVLength Initialization vector length
*/
static encrypt(data: TData, key: string | Buffer, algorithm: TCipherMethod, digest?: TCipherDigest, IVLength?: number): {
iv: string;
data: string;
};
/**
* Decrypt a data with a key and iv
* @param data
* @param key Decryption key
* @param iv Initialization vector
* @param algorithm Encryption algorithm
* @param digest Output digest type
*/
static decrypt(data: TData, key: string | Buffer, iv: string | Buffer, algorithm: TCipherMethod, digest?: TCipherDigest): string;
}