PyHashKit 0.1.0__py3-none-any.whl → 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyhashkit/__init__.py +5 -2
- pyhashkit/cli.py +142 -0
- pyhashkit/hashing.py +36 -4
- {pyhashkit-0.1.0.dist-info → pyhashkit-0.2.0.dist-info}/METADATA +138 -11
- pyhashkit-0.2.0.dist-info/RECORD +10 -0
- pyhashkit-0.2.0.dist-info/entry_points.txt +2 -0
- pyhashkit-0.1.0.dist-info/RECORD +0 -8
- {pyhashkit-0.1.0.dist-info → pyhashkit-0.2.0.dist-info}/WHEEL +0 -0
- {pyhashkit-0.1.0.dist-info → pyhashkit-0.2.0.dist-info}/licenses/LICENSE +0 -0
- {pyhashkit-0.1.0.dist-info → pyhashkit-0.2.0.dist-info}/top_level.txt +0 -0
pyhashkit/__init__.py
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
from .hashing import hash_text, hash_file
|
|
2
|
-
from .
|
|
1
|
+
from .hashing import hash_text, hash_file, algorithms
|
|
2
|
+
from importlib.metadata import version
|
|
3
|
+
|
|
4
|
+
__version__ = version("PyHashKit")
|
|
3
5
|
|
|
4
6
|
__all__ = [
|
|
5
7
|
"hash_text",
|
|
6
8
|
"hash_file",
|
|
9
|
+
"algorithms",
|
|
7
10
|
"__version__"
|
|
8
11
|
]
|
pyhashkit/cli.py
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
|
|
3
|
+
from .hashing import hash_text, hash_file, algorithms
|
|
4
|
+
from importlib.metadata import version
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
__version__ = version("PyHashKit")
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def main():
|
|
11
|
+
parser = argparse.ArgumentParser(
|
|
12
|
+
prog="pyhashkit",
|
|
13
|
+
description="PyHashKit - Hash text and files using various algorithms",
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
parser.add_argument(
|
|
17
|
+
"-v",
|
|
18
|
+
"-V",
|
|
19
|
+
"--version",
|
|
20
|
+
action="store_true",
|
|
21
|
+
help="Show PyHashKit version",
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
subparsers = parser.add_subparsers(
|
|
25
|
+
dest="command",
|
|
26
|
+
help="Available commands",
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
text_parser = subparsers.add_parser(
|
|
30
|
+
"text",
|
|
31
|
+
help="Hash a text string",
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
text_parser.add_argument(
|
|
35
|
+
"text",
|
|
36
|
+
help="Text to hash",
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
text_parser.add_argument(
|
|
41
|
+
"-a",
|
|
42
|
+
"--algorithm",
|
|
43
|
+
default="sha256",
|
|
44
|
+
help="Hash algorithm (default: sha256)",
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
file_parser = subparsers.add_parser(
|
|
48
|
+
"file",
|
|
49
|
+
help="Hash a file",
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
file_parser.add_argument(
|
|
53
|
+
"path",
|
|
54
|
+
help="Path to file",
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
file_parser.add_argument(
|
|
58
|
+
"-a",
|
|
59
|
+
"--algorithm",
|
|
60
|
+
default="sha256",
|
|
61
|
+
help="Hash algorithm (default: sha256)",
|
|
62
|
+
)
|
|
63
|
+
|
|
64
|
+
subparsers.add_parser(
|
|
65
|
+
"commands",
|
|
66
|
+
help="List all available commands",
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
subparsers.add_parser(
|
|
70
|
+
"algorithms",
|
|
71
|
+
help="List all available hashing algorithms",
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
args = parser.parse_args()
|
|
75
|
+
|
|
76
|
+
if args.version:
|
|
77
|
+
print(f"PyHashKit v{__version__}")
|
|
78
|
+
return
|
|
79
|
+
|
|
80
|
+
try:
|
|
81
|
+
if args.command == "text":
|
|
82
|
+
print(hash_text(args.text, args.algorithm))
|
|
83
|
+
|
|
84
|
+
elif args.command in ("algorithms"):
|
|
85
|
+
print("Available Algorithms:")
|
|
86
|
+
|
|
87
|
+
for alg in algorithms():
|
|
88
|
+
print(f" - {alg}")
|
|
89
|
+
|
|
90
|
+
elif args.command == "file":
|
|
91
|
+
print(hash_file(args.path, args.algorithm))
|
|
92
|
+
|
|
93
|
+
elif args.command == "commands":
|
|
94
|
+
print("""
|
|
95
|
+
Available Commands:
|
|
96
|
+
|
|
97
|
+
text Hash a text string
|
|
98
|
+
file Hash a file
|
|
99
|
+
commands Show all commands
|
|
100
|
+
|
|
101
|
+
Flags:
|
|
102
|
+
|
|
103
|
+
-v, -V,
|
|
104
|
+
--version Show version information
|
|
105
|
+
|
|
106
|
+
Options:
|
|
107
|
+
|
|
108
|
+
-a, --algorithm
|
|
109
|
+
Specify hashing algorithm
|
|
110
|
+
(default: sha256)
|
|
111
|
+
|
|
112
|
+
Examples:
|
|
113
|
+
|
|
114
|
+
pyhashkit text "Hello World"
|
|
115
|
+
|
|
116
|
+
pyhashkit text "Hello World" -a md5
|
|
117
|
+
|
|
118
|
+
pyhashkit file example.txt
|
|
119
|
+
|
|
120
|
+
pyhashkit file example.txt -a sha512
|
|
121
|
+
|
|
122
|
+
pyhashkit -v
|
|
123
|
+
""")
|
|
124
|
+
|
|
125
|
+
else:
|
|
126
|
+
parser.print_help()
|
|
127
|
+
|
|
128
|
+
except FileNotFoundError:
|
|
129
|
+
print(f"Error: File not found: {args.path}")
|
|
130
|
+
|
|
131
|
+
except PermissionError:
|
|
132
|
+
print(f"Error: Permission denied: {args.path}")
|
|
133
|
+
|
|
134
|
+
except ValueError as e:
|
|
135
|
+
print(f"Error: {e}")
|
|
136
|
+
|
|
137
|
+
except Exception as e:
|
|
138
|
+
print(f"Unexpected error: {e}")
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
if __name__ == "__main__":
|
|
142
|
+
main()
|
pyhashkit/hashing.py
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import hashlib
|
|
2
2
|
|
|
3
|
+
def algorithms():
|
|
4
|
+
return sorted(hashlib.algorithms_available)
|
|
5
|
+
|
|
6
|
+
|
|
3
7
|
def hash_text(text: str, algorithm: str = "sha256") -> str:
|
|
8
|
+
if not isinstance(text, str):
|
|
9
|
+
raise TypeError(
|
|
10
|
+
"text must be a string"
|
|
11
|
+
)
|
|
12
|
+
|
|
4
13
|
try:
|
|
5
14
|
hash_obj = hashlib.new(algorithm)
|
|
6
15
|
except ValueError:
|
|
@@ -12,8 +21,12 @@ def hash_text(text: str, algorithm: str = "sha256") -> str:
|
|
|
12
21
|
return hash_obj.hexdigest()
|
|
13
22
|
|
|
14
23
|
|
|
15
|
-
|
|
16
24
|
def hash_file(file_path: str, algorithm: str = "sha256") -> str:
|
|
25
|
+
if not isinstance(file_path, str):
|
|
26
|
+
raise TypeError(
|
|
27
|
+
"file_path must be a string"
|
|
28
|
+
)
|
|
29
|
+
|
|
17
30
|
try:
|
|
18
31
|
hash_obj = hashlib.new(algorithm)
|
|
19
32
|
except ValueError:
|
|
@@ -21,8 +34,27 @@ def hash_file(file_path: str, algorithm: str = "sha256") -> str:
|
|
|
21
34
|
f"Unsupported algorithm: {algorithm}"
|
|
22
35
|
)
|
|
23
36
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
37
|
+
try:
|
|
38
|
+
with open(file_path, "rb") as f:
|
|
39
|
+
for chunk in iter(
|
|
40
|
+
lambda: f.read(8192),
|
|
41
|
+
b""
|
|
42
|
+
):
|
|
43
|
+
hash_obj.update(chunk)
|
|
44
|
+
|
|
45
|
+
except FileNotFoundError:
|
|
46
|
+
raise FileNotFoundError(
|
|
47
|
+
f"File not found: {file_path}"
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
except PermissionError:
|
|
51
|
+
raise PermissionError(
|
|
52
|
+
f"Permission denied: {file_path}"
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
except OSError as e:
|
|
56
|
+
raise OSError(
|
|
57
|
+
f"Failed to read file: {e}"
|
|
58
|
+
)
|
|
27
59
|
|
|
28
60
|
return hash_obj.hexdigest()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: PyHashKit
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: A lightweight Python library for hashing text and files using multiple cryptographic algorithms.
|
|
5
5
|
Home-page: https://github.com/Fmasterpro27/PyHashKit
|
|
6
6
|
Author: fmasterpro27
|
|
@@ -30,7 +30,7 @@ Dynamic: requires-python
|
|
|
30
30
|
|
|
31
31
|
# PyHashKit
|
|
32
32
|
|
|
33
|
-
> A lightweight Python library for hashing text and files using multiple cryptographic algorithms.
|
|
33
|
+
> A lightweight Python library and CLI for hashing text and files using multiple cryptographic algorithms.
|
|
34
34
|
|
|
35
35
|
[](https://pypi.org/project/pyhashkit/)
|
|
36
36
|
[](https://pypi.org/project/pyhashkit/)
|
|
@@ -42,6 +42,7 @@ Dynamic: requires-python
|
|
|
42
42
|
|
|
43
43
|
- 🔐 Hash text strings
|
|
44
44
|
- 📄 Hash files of any size
|
|
45
|
+
- 💻 Built-in CLI support
|
|
45
46
|
- ⚡ Supports multiple algorithms
|
|
46
47
|
- 📦 Zero dependencies
|
|
47
48
|
- 🐍 Python 3.8+
|
|
@@ -49,9 +50,17 @@ Dynamic: requires-python
|
|
|
49
50
|
|
|
50
51
|
---
|
|
51
52
|
|
|
53
|
+
## Why PyHashKit?
|
|
54
|
+
|
|
55
|
+
PyHashKit provides a simple and beginner-friendly interface for Python's built-in hashing functionality.
|
|
56
|
+
|
|
57
|
+
Instead of manually working with `hashlib`, you can hash text and files with a single function call or directly from the command line.
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
52
61
|
## Supported Algorithms
|
|
53
62
|
|
|
54
|
-
PyHashKit supports
|
|
63
|
+
PyHashKit supports most algorithms available through Python's built-in `hashlib`.
|
|
55
64
|
|
|
56
65
|
Common examples:
|
|
57
66
|
|
|
@@ -68,6 +77,15 @@ Common examples:
|
|
|
68
77
|
- BLAKE2b
|
|
69
78
|
- BLAKE2s
|
|
70
79
|
|
|
80
|
+
### Not Supported
|
|
81
|
+
|
|
82
|
+
The following algorithms are currently not supported:
|
|
83
|
+
|
|
84
|
+
- SHAKE-128 (`shake_128`)
|
|
85
|
+
- SHAKE-256 (`shake_256`)
|
|
86
|
+
|
|
87
|
+
These algorithms require a custom digest length and are intentionally excluded to keep the API simple and consistent.
|
|
88
|
+
|
|
71
89
|
---
|
|
72
90
|
|
|
73
91
|
## Installation
|
|
@@ -89,9 +107,76 @@ print(hash_file("example.txt"))
|
|
|
89
107
|
|
|
90
108
|
---
|
|
91
109
|
|
|
92
|
-
|
|
110
|
+
# Command Line Interface (CLI)
|
|
111
|
+
|
|
112
|
+
PyHashKit includes a built-in command-line interface for hashing text and files directly from your terminal.
|
|
113
|
+
|
|
114
|
+
## Available Commands
|
|
115
|
+
|
|
116
|
+
```text
|
|
117
|
+
text Hash a text string
|
|
118
|
+
file Hash a file
|
|
119
|
+
commands Show all commands
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Flags
|
|
123
|
+
|
|
124
|
+
```text
|
|
125
|
+
-v, -V, --version
|
|
126
|
+
Show version information
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Options
|
|
93
130
|
|
|
94
|
-
|
|
131
|
+
```text
|
|
132
|
+
-a, --algorithm
|
|
133
|
+
Specify hashing algorithm
|
|
134
|
+
(default: sha256)
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
## Examples
|
|
138
|
+
|
|
139
|
+
Hash text:
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
pyhashkit text "Hello World"
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Hash text using MD5:
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
pyhashkit text "Hello World" -a md5
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
Hash a file:
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
pyhashkit file example.txt
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Hash a file using SHA-512:
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
pyhashkit file example.txt -a sha512
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
Show version information:
|
|
164
|
+
|
|
165
|
+
```bash
|
|
166
|
+
pyhashkit -v
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Show all available commands:
|
|
170
|
+
|
|
171
|
+
```bash
|
|
172
|
+
pyhashkit commands
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
---
|
|
176
|
+
|
|
177
|
+
# Python API
|
|
178
|
+
|
|
179
|
+
## Hash Text
|
|
95
180
|
|
|
96
181
|
```python
|
|
97
182
|
from pyhashkit import hash_text
|
|
@@ -101,7 +186,7 @@ result = hash_text("Hello World")
|
|
|
101
186
|
print(result)
|
|
102
187
|
```
|
|
103
188
|
|
|
104
|
-
|
|
189
|
+
## Hash Text Using MD5
|
|
105
190
|
|
|
106
191
|
```python
|
|
107
192
|
from pyhashkit import hash_text
|
|
@@ -114,7 +199,7 @@ result = hash_text(
|
|
|
114
199
|
print(result)
|
|
115
200
|
```
|
|
116
201
|
|
|
117
|
-
|
|
202
|
+
## Hash File
|
|
118
203
|
|
|
119
204
|
```python
|
|
120
205
|
from pyhashkit import hash_file
|
|
@@ -124,7 +209,7 @@ result = hash_file("example.txt")
|
|
|
124
209
|
print(result)
|
|
125
210
|
```
|
|
126
211
|
|
|
127
|
-
|
|
212
|
+
## Hash File Using SHA-512
|
|
128
213
|
|
|
129
214
|
```python
|
|
130
215
|
from pyhashkit import hash_file
|
|
@@ -139,11 +224,43 @@ print(result)
|
|
|
139
224
|
|
|
140
225
|
---
|
|
141
226
|
|
|
227
|
+
## Version Information
|
|
228
|
+
|
|
229
|
+
```python
|
|
230
|
+
from pyhashkit import __version__
|
|
231
|
+
|
|
232
|
+
print(__version__)
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
---
|
|
236
|
+
|
|
237
|
+
## Available Exports
|
|
238
|
+
|
|
239
|
+
```python
|
|
240
|
+
from pyhashkit import (
|
|
241
|
+
hash_text,
|
|
242
|
+
hash_file,
|
|
243
|
+
algorithms,
|
|
244
|
+
__version__
|
|
245
|
+
)
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
### algorithms
|
|
249
|
+
|
|
250
|
+
Returns a list of supported hashing algorithms available on the current Python installation.
|
|
251
|
+
|
|
252
|
+
```python
|
|
253
|
+
from pyhashkit import algorithms
|
|
254
|
+
|
|
255
|
+
print(algorithms())
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
---
|
|
259
|
+
|
|
142
260
|
## Example Output
|
|
143
261
|
|
|
144
262
|
```text
|
|
145
|
-
|
|
146
|
-
d62c65bf0bcda32b57b277d9ad9f146e
|
|
263
|
+
a591a6d40bf420404a011733cfb7b190d62c65bf0bcda32b57b277d9ad9f146e
|
|
147
264
|
```
|
|
148
265
|
|
|
149
266
|
---
|
|
@@ -155,6 +272,7 @@ PyHashKit/
|
|
|
155
272
|
├── pyhashkit/
|
|
156
273
|
│ ├── __init__.py
|
|
157
274
|
│ ├── hashing.py
|
|
275
|
+
│ ├── cli.py
|
|
158
276
|
│ └── version.py
|
|
159
277
|
├── tests/
|
|
160
278
|
│ └── test_hashing.py
|
|
@@ -170,12 +288,21 @@ PyHashKit/
|
|
|
170
288
|
Contributions, bug reports, and feature requests are welcome.
|
|
171
289
|
|
|
172
290
|
1. Fork the repository
|
|
173
|
-
2. Create a branch
|
|
291
|
+
2. Create a new branch
|
|
174
292
|
3. Make your changes
|
|
175
293
|
4. Submit a pull request
|
|
176
294
|
|
|
177
295
|
---
|
|
178
296
|
|
|
297
|
+
## Author
|
|
298
|
+
|
|
299
|
+
Developed by **JackMa**
|
|
300
|
+
|
|
301
|
+
GitHub:
|
|
302
|
+
https://github.com/Fmasterpro27
|
|
303
|
+
|
|
304
|
+
---
|
|
305
|
+
|
|
179
306
|
## Links
|
|
180
307
|
|
|
181
308
|
Homepage:
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
pyhashkit/__init__.py,sha256=71gwuHE-9hbMSMvgA58m6Ljb6NN1pJ7ildSCVq9YMMo,223
|
|
2
|
+
pyhashkit/cli.py,sha256=4G-9qkvjmSfBT9UjjvlSWr3HZRsH-wbsXysMUN8TZ8k,2942
|
|
3
|
+
pyhashkit/hashing.py,sha256=BfILbuLyEOMt4VM6aHDZNWsGmMiFhczeUXdspWn-fa0,1445
|
|
4
|
+
pyhashkit/version.py,sha256=Pru0BlFBASFCFo7McHdohtKkUtgMPDwbGfyUZlE2_Vw,21
|
|
5
|
+
pyhashkit-0.2.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
6
|
+
pyhashkit-0.2.0.dist-info/METADATA,sha256=veKhERdJNI6vOtcRdDL2PvnCY5FMJ31A4HwN1Egb2yc,5862
|
|
7
|
+
pyhashkit-0.2.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
8
|
+
pyhashkit-0.2.0.dist-info/entry_points.txt,sha256=J0l-83OwffVqEfIC6Zq6CjBTarX_S0eqkUVaPb9ASv4,49
|
|
9
|
+
pyhashkit-0.2.0.dist-info/top_level.txt,sha256=i4mBVLg3ASdKUsNh8G4uPlNWRI1_a1rGhpQVPJ1kIac,10
|
|
10
|
+
pyhashkit-0.2.0.dist-info/RECORD,,
|
pyhashkit-0.1.0.dist-info/RECORD
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
pyhashkit/__init__.py,sha256=ln2HpPAwaRwaD34N6JOOSFBEzmR7XqmJNMk1bWJ3DkQ,148
|
|
2
|
-
pyhashkit/hashing.py,sha256=ogXXqXtCJ7_FT7L8EfaCX50IipoOffTAC4EsnXErPy4,725
|
|
3
|
-
pyhashkit/version.py,sha256=Pru0BlFBASFCFo7McHdohtKkUtgMPDwbGfyUZlE2_Vw,21
|
|
4
|
-
pyhashkit-0.1.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
5
|
-
pyhashkit-0.1.0.dist-info/METADATA,sha256=MzpM310DedDVRFK1ARxZCxHLyS4j7Sn_Yc4yXKD2KTI,3829
|
|
6
|
-
pyhashkit-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
7
|
-
pyhashkit-0.1.0.dist-info/top_level.txt,sha256=i4mBVLg3ASdKUsNh8G4uPlNWRI1_a1rGhpQVPJ1kIac,10
|
|
8
|
-
pyhashkit-0.1.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|