# encryption | Stacks.js 1.4.1 Library Reference
Documentation for Stacks.js 1.4.1 Library Reference

# @stacks/encryption

Encryption functions used by Stacks.js packages.

## Installation

    npm install @stacks/cli

## Index

### Classes

- NodeCryptoSha2Hash
- WebCryptoSha2Hash

### Interfaces

- EncryptContentOptions
- EncryptionOptions
- Sha2Hash

### Type aliases

- GetRandomBytes

### Functions

- createSha2Hash
- decryptContent
- encryptContent
- getBase64OutputLength
- hashSha256Sync
- hashSha512Sync
- randomBytes

## Type aliases

### GetRandomBytes

GetRandomBytes: (count: number) => Buffer

- Defined in packages/encryption/src/cryptoRandom.ts:8

Optional function to generate cryptographically secure random bytes

#### Type declaration

- - (count: number): Buffer

  - #### Parameters

    - ##### count: number

    #### Returns Buffer

## Functions

### createSha2Hash

- createSha2Hash(): Promise< Sha2Hash >

- - Defined in packages/encryption/src/sha2Hash.ts:61

  #### Returns Promise< Sha2Hash >

### decryptContent

- decryptContent(content: string, options?: { privateKey?: string }): Promise<string | Buffer>

- - Defined in packages/encryption/src/encryption.ts:111

  Decrypts data encrypted with `encryptContent` with the transit private key.

  #### Parameters

  - ##### content: string

    encrypted content.

  - ##### Optional options: { privateKey?: string }

    - ##### Optional privateKey?: string

      the hex string of the ECDSA private key to use for decryption. If not provided, will use user's appPrivateKey.

  #### Returns Promise<string | Buffer>

  decrypted content.

### encryptContent

- encryptContent(content: string | Buffer, options?: EncryptContentOptions ): Promise<string>

- - Defined in packages/encryption/src/encryption.ts:59

  Encrypts the data provided with the app public key.

  #### Parameters

  - ##### content: string | Buffer

    data to encrypt

  - ##### Optional options: EncryptContentOptions

  #### Returns Promise<string>

  Stringified ciphertext object

### getBase64OutputLength

- getBase64OutputLength(inputByteLength: number): number

- - Defined in packages/encryption/src/utils.ts:18

  Calculate the base64 encoded string length for a given input length. This is equivalent to the byte length when the string is ASCII or UTF8-8 encoded.

  #### Parameters

  - ##### inputByteLength: number

  #### Returns number

### hashSha256Sync

- hashSha256Sync(data: Buffer): Buffer

- - Defined in packages/encryption/src/sha2Hash.ts:70

  #### Parameters

  - ##### data: Buffer

  #### Returns Buffer

### hashSha512Sync

- hashSha512Sync(data: Buffer): Buffer

- - Defined in packages/encryption/src/sha2Hash.ts:76

  #### Parameters

  - ##### data: Buffer

  #### Returns Buffer

### Const randomBytes

- randomBytes(size: number): Buffer
- randomBytes(size: number, callback: (err: Error | null, buf: Buffer) => void): void

- - Defined in node_modules/@types/randombytes/index.d.ts:12

  #### Parameters

  - ##### size: number

  #### Returns Buffer

- - Defined in node_modules/@types/randombytes/index.d.ts:12

  #### Parameters

  - ##### size: number

  - ##### callback: (err: Error | null, buf: Buffer) => void

    - - (err: Error | null, buf: Buffer): void

      - #### Parameters

        - ##### err: Error | null

        - ##### buf: Buffer

        #### Returns void

Generated using TypeDoc