Service for handling cryptographic operations.

Remarks

This service provides methods for hashing, comparing, and generating salt for cryptographic operations.

Constructors

Methods

Constructors

Methods

  • Compare a value with a hashed value.

    Parameters

    • value: string

      The value to compare.

    • hash: string

      The hashed value to compare against.

    Returns boolean

    true if the values match, false otherwise.

    Remarks

    This method compares a plain text value with a hashed value by rehashing the plain text value with the salt extracted from the hashed value.

    Example

    // Example usage of compare method
    const hashedValue = 'value:salt'
    const isMatch = cryptoService.compare('mySecretValue', hashedValue);
  • Generate a random salt value of the specified number of rounds.

    Parameters

    • rounds: number

      The number of rounds to generate the salt.

    Returns string

    The generated salt value.

    Remarks

    This method generates a random salt value using the crypto module.

    Example

    // Example usage of genSalt method
    const randomSalt = cryptoService.genSalt(10);
  • Generate a hashed value using SHA-512 algorithm with an optional salt.

    Parameters

    • value: string

      The value to be hashed.

    • Optional salt: string

      An optional salt value. If not provided, a random salt will be generated.

    Returns string

    The hashed value appended with the salt.

    Remarks

    This method uses the SHA-512 algorithm to hash the input value with the provided or generated salt.

    Example

    // Example usage of hash method
    const salt = cryptoService.genSalt(8)
    const hashedValue = cryptoService.hash('mySecretValue', salt);

Generated using TypeDoc