hash

package
v1.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 21, 2025 License: Apache-2.0 Imports: 9 Imported by: 1

Documentation

Overview

Package hash provides time-based hashing utilities with optional encryption support. It implements a custom encoding scheme that embeds timestamp information along with data, allowing for data integrity verification and timestamp extraction.

Index

Constants

This section is empty.

Variables

View Source
var CryptoTimeHashPadding = byte(0x59)

CryptoTimeHashPadding is the padding byte used in encrypted time hash operations. This value is used for both padding data and as part of the integrity check.

View Source
var CryptoTimeHashXBit = byte(0x53)

CryptoTimeHashXBit is the XOR bit used for checksum calculations in time hashes. This value helps ensure data integrity during encoding and decoding operations.

View Source
var TimeHashBase = []byte{75, 79, 78, 83, 73, 84, 69, 89}

TimeHashBase is the base key used for XOR operations in the time hash algorithm. This constant provides a fixed seed for consistent encoding/decoding operations.

Functions

func CryptoTimeHash

func CryptoTimeHash(data []byte, timestamp int64, key []byte) string

CryptoTimeHash encodes data with an embedded timestamp using AES encryption. This function provides enhanced security by encrypting the data before applying the time hash algorithm, making it suitable for sensitive information.

Parameters:

  • data: The byte slice to be encoded and encrypted (cannot be nil or empty)
  • timestamp: Unix timestamp in seconds (must be greater than 0)
  • key: Encryption key (cannot be nil or empty, will be SHA256 hashed to 32-byte key)

Returns:

  • A base62-encoded string containing the encrypted and hashed data with embedded timestamp
  • Empty string if input validation fails or encryption fails

The encoding process:

  1. Validates all input parameters
  2. Encrypts the data using AES-256-CBC with the provided key
  3. Applies the TimeHash algorithm to the encrypted data
  4. Returns the base62-encoded result

Security features:

  • AES-256-CBC encryption with random IV
  • SHA256 key derivation for consistent 32-byte keys
  • Integrity validation through checksums

func DataOfCryptoTimeHash

func DataOfCryptoTimeHash(encoded string, key []byte) []byte

func DataOfTimeHash

func DataOfTimeHash(encoded string) []byte

func FindDataOfTimeHash

func FindDataOfTimeHash(encoded string, key []byte) []byte

func TimeHash

func TimeHash(data []byte, timestamp int64) string

TimeHash encodes data with an embedded timestamp using a custom algorithm. The function combines the data with the timestamp and applies XOR operations with padding and checksum validation to create a secure, time-stamped hash.

Parameters:

  • data: The byte slice to be encoded (cannot be nil or empty)
  • timestamp: Unix timestamp in seconds (must be greater than 0)

Returns:

  • A base62-encoded string containing the hashed data with embedded timestamp
  • Empty string if input validation fails

The encoding process:

  1. Validates input parameters
  2. Applies padding to align data to 8-byte boundaries
  3. XORs data segments with timestamp-derived keys
  4. Adds integrity checksums
  5. Encodes result using base62 encoding

func TimestampOfTimeHash

func TimestampOfTimeHash(encoded string) int64

func ValidateTimeHash

func ValidateTimeHash(encoded string) bool

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL