---
title: Construct a salting SaltShaker
summary: Build a SaltShaker instance pre-populated with the hex-encoded parts of a create date, ready to salt a hash.
status: draft
owner: SAIF Platform Team
last_reviewed: 2026-10-02
library: SAIF.NetCore.HashUtil
reference_type: package
operation_id: OP-HU-01
trigger: Caller needs to salt a hash
---

# Construct a salting SaltShaker

This operation builds a `SaltShaker` instance whose `_dateParts` dictionary is populated from a caller-supplied create date, which is the only state `SaltHash` (OP-HU-03) needs to embed that date into a hash string. In-repo, `SystemHashService.ComputeHash` is the sole caller, passing `DateTime.Now`.

| Field | Value |
| --- | --- |
| **Operation ID** | OP-HU-01 |
| **Trigger** | Caller needs to salt a hash (in-repo: `SystemHashService.ComputeHash`, passing `DateTime.Now`) |
| **Inputs** | `createDate` (`DateTime`) |
| **Outputs** | `SaltShaker` instance with `_random` and populated `_dateParts` |
| **Primary components** | `SaltShaker.SaltShaker(DateTime createDate)` |
| **Entry point** | `src/SAIF.NetCore.HashUtil/SAIF.NetCore.HashUtil/SaltShaker.cs` |

## Steps

1. Chain to the parameterless constructor, which creates a new `System.Random` instance used later for insertion positions and pad characters.
2. Create the `_dateParts` dictionary.
3. For each date part, format `createDate` with the current culture and hex-encode it, inserting entries in this order: Minute (`"mm"`), Year (`"yyyy"`), Day (`"dd"`), Millisecond (`"fff"`), Second (`"ss"`), Hour (`"HH"`, 24-hour), Month (`"MM"`) ([BR-HU-02](../business-rules.md#br-hu-02-fixed-hex-encoded-date-part-lengths), [BR-HU-03](../business-rules.md#br-hu-03-millisecond-precision%2C-24-hour%2C-culture-sensitive-timestamp)).

## Process flow

The following diagram visualizes this operation's control flow.

```mermaid
flowchart TD
	Start([Caller needs to salt a hash]) --> S1["Chain to parameterless constructor:<br>create System.Random"]
	S1 --> S2[Create _dateParts dictionary]
	S2 --> S3["Hex-encode each date part in<br>Minute, Year, Day, Millisecond,<br>Second, Hour, Month order"]
	S3 --> EndOk([Instance ready for SaltHash])
```

## Failure and edge-case behavior
- No explicit error handling exists in this constructor; a `null` `createDate` is not possible (`DateTime` is a value type), so this operation has no documented failure path of its own.

## Related documentation
- [Operations and processes](../operations-processes.md)
- [Business rules](../business-rules.md)

## Sources
- `src/SAIF.NetCore.HashUtil/SAIF.NetCore.HashUtil/SaltShaker.cs`
- `src/SAIF.NetCore.SystemHash/SAIF.NetCore.SystemHash/SAIF.NetCore.SystemHash/SystemHashService.cs`
