Skip to content

Hmac-Md4

Hmac-Md4 is a message authentication code algorithm based on md4. dongle supports the standard md4 message authentication code algorithm and provides multiple output formats.

Note: The WithKey method must be called before ByMd4

Input Data

go
// Input string
hasher := dongle.Hash.FromString("hello world").WithKey([]byte("dongle")).ByMd4()
// Input byte slice
hasher := dongle.Hash.FromBytes([]byte("hello world")).WithKey([]byte("dongle")).ByMd4()
// Input file stream
file, _ := os.Open("test.txt")
hasher := dongle.Hash.FromFile(file).WithKey([]byte("dongle")).ByMd4()

// Check HMAC error
if hasher.Error != nil {
	fmt.Printf("HMAC error: %v\n", hasher.Error)
	return
}

Output Data

go
// Output Hex encoded string
hasher.ToHexString() // 7a9df5247cbf76a8bc17c9c4f5a75b6b
// Output Hex encoded byte slice
hasher.ToHexBytes()  // []byte("7a9df5247cbf76a8bc17c9c4f5a75b6b")

// Output Base64 encoded string
hasher.ToBase64String() // ep31JHy/dqi8F8nE9adbaw==
// Output Base64 encoded byte slice
hasher.ToBase64Bytes()  // []byte("ep31JHy/dqi8F8nE9adbaw==")

// Output raw string
hasher.ToRawString()
// Output raw byte slice
hasher.ToRawBytes()

Released under the MIT License, unauthorized reproduction is prohibited in any form