Ver Mensaje Individual
  #18  
Antiguo 05-10-2024
navbuoy navbuoy is offline
Miembro
 
Registrado: mar 2024
Posts: 280
Reputación: 2
navbuoy Va por buen camino
chatgpt me dio esta opcion con los componentes INDY

Código:
AnsiString CodificarSHA256(const AnsiString &texto)
{
    // Crea una instancia de la clase de hash SHA256
    TIdHashSHA256 *sha256 = new TIdHashSHA256();
    AnsiString resultado;

    try {
        // Convierte el AnsiString en un TIdBytes manualmente
        TIdBytes buffer;
        buffer.Length = texto.Length(); // Ajusta el tamaño del buffer

        for (int i = 0; i < texto.Length(); i++)
        {
            buffer[i] = static_cast<unsigned char>(texto[i + 1]); // Convierte cada carácter
        }

        // Calcula el hash en un TIdBytes
        TIdBytes hash = sha256->HashBytes(buffer);

        // Convierte el hash a una cadena hexadecimal
        resultado = sha256->HashBytesAsHex(hash);
    }
    __finally {
        delete sha256;  // Libera la memoria
    }

    return resultado;
}

Uso de la funcion:
Cita:
AnsiString texto = "MiTextoSeguro";
AnsiString hash = CodificarSHA256(texto);
ShowMessage(hash);

Última edición por navbuoy fecha: 05-10-2024 a las 02:42:36.
Responder Con Cita