@vvlad1973/crypto - v2.4.0
    Preparing search index...

    Class Crypto

    Class representing a cryptographic utility for encrypting and decrypting text.

    The password used for key derivation or an options object.

    The salt used for key derivation.

    The hash algorithm to use for key derivation.

    The number of iterations to use for key derivation.

    The length of the derived key in bytes.

    The initialization vector for the AES encryption.

    Index

    Constructors

    • Parameters

      • password: string
      • salt: string
      • Optionalalgorithm: string
      • Optionaliterations: number
      • OptionalkeyLength: number
      • Optionaliv: number | Buffer

      Returns Crypto

    • Parameters

      Returns Crypto

    Methods

    • Encrypt a text string. Uses the IV supplied at construction time (fixed or random-at-construct). The IV is not embedded in the output — both sides must use the same IV. For persistent storage use encryptStorable instead.

      Parameters

      • text: string

        The plain text to encrypt.

      Returns string

      The encrypted text as a hex string.

    • Decrypt an encrypted text string produced by encrypt. Uses the IV supplied at construction time.

      Parameters

      • text: string

        The encrypted text as a hex string.

      Returns string

      The decrypted plain text.

    • Encrypts text and prepends a fresh random IV to the output.

      Use this method when the ciphertext will be stored (database, file, etc.) and retrieved later in a different process instance. A new random IV is generated for every call, so repeated encryptions of the same plaintext produce different ciphertexts — no IV reuse across records.

      Output format: hex( IV[16 bytes] || ciphertext[N bytes] )

      The construction-time IV is not used by this method.

      Parameters

      • text: string

        The plain text to encrypt.

      Returns string

      Hex string containing the prepended IV and ciphertext.

    • Decrypts a value produced by encryptStorable.

      Extracts the first 16 bytes as the IV, then decrypts the remainder. The construction-time IV is not used by this method.

      Parameters

      Returns string

      The decrypted plain text.

      When the input is shorter than 16 bytes (32 hex chars).

    • Returns a UUID ver.4 string.

      Returns string

      UUID ver.4 string.