Para calcular un hash SHA-512 en Python con una semilla (o sal) para fortalecer la seguridad del hash, puedes usar la biblioteca estándar hashlib
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
import hashlib def calcular_hash_sha512(texto, semilla=''): # Convertir el texto y la semilla a bytes texto_bytes = texto.encode('utf-8') semilla_bytes = semilla.encode('utf-8') # Concatenar el texto con la semilla texto_semilla = texto_bytes + semilla_bytes # Calcular el hash SHA-512 hash_object = hashlib.sha512() hash_object.update(texto_semilla) hash_resultado = hash_object.hexdigest() return hash_resultado # Ejemplo de uso texto_original = "Hola, mundo!" semilla = "1234567890" # Ejemplo de una semilla hash_resultado = calcular_hash_sha512(texto_original, semilla) print(f"Texto original: {texto_original}") print(f"Semilla: {semilla}") print(f"Hash SHA-512 con semilla: {hash_resultado}") |
