networking
Version:
Library for typed, event-based networking between a server and clients.
36 lines (35 loc) • 1.41 kB
TypeScript
/// <reference types="node" />
import { Json } from './serialize';
export declare class Encryption {
/**
* Encrypts data with the given key, and returns the ciphered bytes as a buffer. The first 16 bytes in the buffer
* will always be the initialization vector used during encryption. The data is padded automatically with PKCS#7.
*
* @param key Must equal 256 bits
* @param data
*/
static encrypt(key: Buffer | string, data: Buffer | string): Promise<Buffer>;
/**
* Decrypts data with the given key, and returns the original data as a buffer. The first 16 bytes in the ciphered
* data must be the initialization vector that was used to encrypt the message. The data is padded automatically
* with PKCS#7.
*
* @param key Must equal 256 bits
* @param data
*/
static decrypt(key: Buffer | string, data: Buffer | string): Promise<Buffer>;
/**
* Asynchronously generates a secure, random initialization vector for encryption.
*/
static generateIV(): Promise<Buffer>;
/**
* Asynchronously generates a secure, random string of the specified number of bytes.
*/
static generateRandom(bytes: number): Promise<Buffer>;
/**
* Generates a 256-bit key from a password of any serializable type and size.
*
* @param password
*/
static generateKey(password: Json): string;
}