MD5 Hash a Field With a Given Value

MD5 hash a field with a given value using the crypto:md5() function

Query

logscale
a := "Hello, world!"
| crypto:md5(a)

Introduction

In LogScale it is possible to encode strings using different algorithms such as MD5, SHA-1, and SHA-256 and create a hash; also called a fingerprint. The MD5 hash function is the weakest of the three, whereas SHA-256 is the strongest. The crypto:sha256() function is used to create the SHA-256 hash by taking a string of any length and encoding it into a 256-bit fingerprint. The fingerprint is returned as hexadecimal characters. Encoding the same string using the SHA-256 algorithm will always result in the same 256-bit hash output (64 hexadecimal digits).

In this example, the crypto:md5() function is used to hash the field a with value Hello, world! and convert the result into _md5.

Step-by-Step

  1. Starting with the source repository events.

  2. flowchart LR; %%{init: {"flowchart": {"defaultRenderer": "elk"}} }%% repo{{Events}} 0[\Add Field/] 1>Augment Data] result{{Result Set}} repo --> 0 0 --> 1 1 --> result style 0 fill:#ff0000,stroke-width:4px,stroke:#000;
    logscale
    a := "Hello, world!"

    Assigns the value Hello, world! to the field a.

  3. flowchart LR; %%{init: {"flowchart": {"defaultRenderer": "elk"}} }%% repo{{Events}} 0[\Add Field/] 1>Augment Data] result{{Result Set}} repo --> 0 0 --> 1 1 --> result style 1 fill:#ff0000,stroke-width:4px,stroke:#000;
    logscale
    | crypto:md5(a)

    Performs a cryptographic MD5-hashing of a:= "Hello, world!". The output value would be _md5 = "6cd3556deb0da54bca060b4c39479839"

  4. Event Result set.

Summary and Results

The query is used to encode a string using the MD5 hash. The hash generators MD5, SHA-1, and SHA-256 are, for example, useful for encoding passwords or representing other strings in the system as hashed values.