hash_and_salt_sha_256: Salt and hash a value

View source: R/hash-and-salt.R

hash_and_salt_sha_256R Documentation

Salt and hash a value

Description

Uses digest::digest() to hash as (salted) value, using 'SHA-256'. If the x isn't already a character vector, it's converted to one (even if x inherits from character).

This approach protects the actual value of x, while still allowing a downstream user to determine which cells were derived from the same x.

For example, suppose a patient's mrn of '111' is hashed, and the output is 'abc'. (To view it's real value, execute OuhscMunge::hash_and_salt_sha_256(111).) When given the value 'abc', is it computational infeasible to determine the input had been '111' (especially when salted). However, when you see that two visits have an mrn of 'abc', you can determine the same patient generated both visits.

Usage

hash_and_salt_sha_256(
  x,
  salt = "",
  min_characters = 1L,
  max_characters = 2048L,
  na_if = c("")
)

Arguments

x

A vector of values to convert. it should be a character vector, or something that can be cast to a character vector.

salt

A single-element character vector.

min_characters

The minimum count of characters that x is allowed to be. Must be an integer or numeric data type.

max_characters

The maximum count of characters that x is allowed to be. Must be an integer or numeric data type.

na_if

A vector of characters that should produce a has of NA_character_. Default of c("").

Value

A character vector.

Author(s)

Will Beasley

References

cryptographic hash function and salts.

Examples

x    <- letters[1:5]

salt <- "abc123"
hash_and_salt_sha_256(x, salt)

# If an unsalted hash is desired, leave the `salt` parameter blank
hash_and_salt_sha_256(x)

# By default, a zero-length character produces hash of NA.
hash_and_salt_sha_256(c("a", "", "c"))

OuhscBbmc/OuhscMunge documentation built on Dec. 5, 2024, 4:34 a.m.