{"id":49497825,"url":"https://github.com/ronaldstoner/selfhash-python","last_synced_at":"2026-05-01T10:33:18.225Z","repository":{"id":198519448,"uuid":"700959189","full_name":"ronaldstoner/selfhash-python","owner":"ronaldstoner","description":"A self-hashing python script","archived":false,"fork":false,"pushed_at":"2025-02-24T22:32:02.000Z","size":544,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-09-25T10:35:21.220Z","etag":null,"topics":["hash","hashlib","python"],"latest_commit_sha":null,"homepage":"https://ron.stoner.com","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ronaldstoner.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-10-05T16:18:19.000Z","updated_at":"2025-05-17T21:15:18.000Z","dependencies_parsed_at":"2023-10-10T16:11:10.738Z","dependency_job_id":null,"html_url":"https://github.com/ronaldstoner/selfhash-python","commit_stats":null,"previous_names":["ronaldstoner/selfhash-python"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/ronaldstoner/selfhash-python","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ronaldstoner%2Fselfhash-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ronaldstoner%2Fselfhash-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ronaldstoner%2Fselfhash-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ronaldstoner%2Fselfhash-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ronaldstoner","download_url":"https://codeload.github.com/ronaldstoner/selfhash-python/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ronaldstoner%2Fselfhash-python/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32494271,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-30T13:12:12.517Z","status":"online","status_checked_at":"2026-05-01T02:00:05.856Z","response_time":64,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hash","hashlib","python"],"created_at":"2026-05-01T10:33:17.147Z","updated_at":"2026-05-01T10:33:18.207Z","avatar_url":"https://github.com/ronaldstoner.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SelfHash\n\nSelfHash is a Python package that allows you to hash your Python scripts and verify them. It's designed to provide an additional layer of security by ensuring that your script's code has not been tampered with. If the hash does not match the known good hash then the script will immediately exit and prevent further execution.\n\n## Installation\n```bash\npip install selfhash\n```\n\n## Installation From Source\n\nYou can also choose to install SelfHash from source with:\n\n```bash\ngit clone https://github.com/ronaldstoner/selfhash-python.git\ncd selfhash-python\npip install .\n```\n\n## Integrating SelfHash Into Your Scripts\n\nTo use SelfHash in your scripts, you need to follow two steps:\n\n1. **Add the Hash Line:** At the top of your script file, include the following special line of code: `# Hash: INSERT_HASH_HERE`. This line serves as a placeholder for the hash of your script's code. \n\n2. **Use the SelfHash Module:** Import the SelfHash module in your script, create a new instance of the SelfHash class, and then call the `hash` method on this instance, passing `__file__` as an argument. This will calculate the hash of your script and verify it against the stored hash.\n\nHere's an example:\n\n```python\n# Hash: INSERT_HASH_HERE\nimport selfhash\n\nhasher = selfhash.SelfHash(bypass_salt=False) # Always prompt for salt when set to False\nhasher.hash(__file__)\n```\n\nWhen you run a script that uses SelfHash for the first time, it will generate a hash of the script. You then need to insert this hash into the `# Hash: ` comment (leave it commented) of the script's code. This hash is then used for verification in subsequent runs.\n\nIf the hash of the script matches the known good hash, the script will print `PASS: The program is verified and true.` and continue execution. If the hash does not match, the script will print `FAIL: The source code may have been tampered with.` and immediately exit.\n\n## Salt/Passphrase\n\nWhen you run the `hash` method, it will prompt you to enter a salt/passphrase for the hash calculation. This is an optional step that you can use to add an extra layer of security to your hash. \n\nIf you choose to provide a salt/passphrase, it will be used in the calculation of the hash of your script. This means that even if someone else has the exact same script code, they won't be able to generate the same hash unless they also know your salt/passphrase. \n\nIf you choose not to provide a salt/passphrase, you can simply press Enter when prompted and the hash will be calculated based only on your script's code.\n\nRemember - if you use a salt/passphrase you should use the same salt/passphrase every time you run the script, otherwise the hash will be different and the script will fail the verification. This salt/passphrase should be stored securely for future retrieval.\n\n## Bypass Salt/Passphrase\n\nIn some cases, you might want to bypass the salt/passphrase prompt. You can do this by setting the bypass_salt parameter to True when you create an instance of the SelfHash class.\n\nHere's an example:\n\n```python\n\n# Hash: INSERT_HASH_HERE\nimport selfhash\n\nhasher = selfhash.SelfHash(bypass_salt=True)\nhasher.hash(__file__)\n```\n\nWhen you set `bypass_salt` to `True`, the hash method will not prompt you for a salt/passphrase and will calculate the hash based only on your script's code. This can be useful in automated environments where user input is not possible.\n\nNote: If you bypass the salt/passphrase, you won't be able to use a salt/passphrase for the hash calculation. If you've previously run the hash method with a salt/passphrase, the hash will be different when you bypass the salt/passphrase, and the script will fail the verification. Be sure to use the same bypass_salt setting every time you run the script.\n\n\n## Verifying The SelfHash Module\n\nTo ensure the integrity of the SelfHash module itself, we provide a script named `verify_self.py`. This script uses SelfHash to verify the hash of the `selfhash/selfhash.py` file.\n\nIf the hash of `selfhash/selfhash.py` matches the known hash at the top of the file, `verify_self.py` will print a message saying, `The hash inside of selfhash/selfhash.py matches and looks correct.`\n\nTo run `verify_self.py`, use the following command without any salt (no passphrase is set):\n\n```bash\npython verify_self.py\n```\n\n## Screenshots\n### Hashing A Script For The First Time\n\u003cimg src=\"https://github.com/ronaldstoner/selfhash-python/blob/main/img/1.png?raw=true\" /\u003e\n\n### Verifying The Hash And Executing\n\u003cimg src=\"https://github.com/ronaldstoner/selfhash-python/blob/main/img/2.png?raw=true\" /\u003e\n\n### Preventing Execution Of A Modified Script Or Incorrect Salt\n\u003cimg src=\"https://github.com/ronaldstoner/selfhash-python/blob/main/img/3.png?raw=true\" /\u003e\n\n### Verifying SelfHash module itself (no seed/passphrase)\n\u003cimg src=\"https://github.com/ronaldstoner/selfhash-python/blob/main/img/4.png?raw=true\" /\u003e\n\n## Note\nIt's important to note that this script is only a part of a comprehensive security strategy and should not be solely relied upon to ensure the integrity and security of your code.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fronaldstoner%2Fselfhash-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fronaldstoner%2Fselfhash-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fronaldstoner%2Fselfhash-python/lists"}