Ktor basic auth from UserHashedTableAuth

Viewed 564

In this sample from Ktor website https://ktor.io/samples/feature/auth.html they use an account "test" with password "test" as example.

@UseExperimental(KtorExperimentalAPI::class)
val hashedUserTable = UserHashedTableAuth(
    getDigestFunction("SHA-256") { "ktor${it.length}" },
    table = mapOf(
        "test" to Base64.getDecoder().decode("GSjkHCHGAxTTbnkEDBbVYd+PUFRlcWiumc4+MWE9Rvw=") // sha256 for "test"
    )
)

I need to create another entry, but I can't figure out how they got that hash. I tried to sha256 the word "test", salted or not, tried to base64 the result... Nothing matches that hash so I'm unable to create another user.

Anyone could enlighten me here on how to create a compatible hash with that code?

1 Answers

After a lot of try and errors... Here's how to duplicate that:

echo -n ktor4test | openssl dgst -binary -sha256 | openssl base64

I hope this helps someone in the future not to waste the same time as myself.

Related