Skip to main content

A small python library for calculating the secret hash required for the amazon cognito's user and password authentication

Project description

Secret Hash Generator

This function, calculate_secret_hash, generates a secure hash using HMAC (Hash-based Message Authentication Code) and SHA-256. It's useful for authentication and securely verifying user credentials for Amazon Cognito.


Function Overview

calculate_secret_hash

This function creates a secret hash by combining the username and client ID, secured with a client secret key.

Parameters

  • client_id (str):
    The unique identifier for the client.

  • client_secret (str):
    The secret key associated with the client ID, used for hashing.

  • username (str):
    The username or user identifier to include in the hash computation.

Returns

  • A base64-encoded string representing the HMAC SHA-256 hash.

Dependencies

The function uses Python's standard library, so no external installations are required. Specifically, it uses:

  • hmac
  • hashlib
  • base64

Usage

from mylibrary import calculate_secret_hash

# Example inputs
client_id = "exampleClientId123"
client_secret = "superSecretKey456"
username = "user@example.com"

# Generate the secret hash
secret_hash = calculate_secret_hash(client_id, client_secret, username)
print(f"Generated Secret Hash: {secret_hash}")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cognitohashcalculator-1.0.0.tar.gz (2.1 kB view details)

Uploaded Source

File details

Details for the file cognitohashcalculator-1.0.0.tar.gz.

File metadata

  • Download URL: cognitohashcalculator-1.0.0.tar.gz
  • Upload date:
  • Size: 2.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for cognitohashcalculator-1.0.0.tar.gz
Algorithm Hash digest
SHA256 a9c90c9f7f1eb26d973ef213abb3566334574d0f7762a66ceb8289b16a3515ae
MD5 07e2fe6185a7bf12ee54e63e57f2fafc
BLAKE2b-256 b450e3390d38dbe84f00fff065c2272ff9b565e3b01a9f360f9645e626b774f0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page