fast-cryptography 0.1.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.
Files changed (50) hide show
  1. fast_cryptography/__init__.py +81 -0
  2. fast_cryptography/algorithms/__init__.py +1 -0
  3. fast_cryptography/algorithms/asymmetric/__init__.py +19 -0
  4. fast_cryptography/algorithms/asymmetric/ecc.py +55 -0
  5. fast_cryptography/algorithms/asymmetric/ed25519.py +58 -0
  6. fast_cryptography/algorithms/asymmetric/rsa.py +59 -0
  7. fast_cryptography/algorithms/cryptorandom/__init__.py +17 -0
  8. fast_cryptography/algorithms/cryptorandom/byte.py +20 -0
  9. fast_cryptography/algorithms/cryptorandom/choice.py +21 -0
  10. fast_cryptography/algorithms/cryptorandom/hex_bytes.py +34 -0
  11. fast_cryptography/algorithms/cryptorandom/iv.py +12 -0
  12. fast_cryptography/algorithms/cryptorandom/nonce.py +9 -0
  13. fast_cryptography/algorithms/cryptorandom/randint.py +19 -0
  14. fast_cryptography/algorithms/cryptorandom/salt.py +11 -0
  15. fast_cryptography/algorithms/encoding/__init__.py +17 -0
  16. fast_cryptography/algorithms/encoding/base16.py +17 -0
  17. fast_cryptography/algorithms/encoding/base32.py +17 -0
  18. fast_cryptography/algorithms/encoding/base45.py +20 -0
  19. fast_cryptography/algorithms/encoding/base58.py +17 -0
  20. fast_cryptography/algorithms/encoding/base64.py +26 -0
  21. fast_cryptography/algorithms/encoding/base85.py +17 -0
  22. fast_cryptography/algorithms/encoding/baseA85.py +17 -0
  23. fast_cryptography/algorithms/hashes/__init__.py +21 -0
  24. fast_cryptography/algorithms/hashes/blake2b.py +8 -0
  25. fast_cryptography/algorithms/hashes/blake2s.py +9 -0
  26. fast_cryptography/algorithms/hashes/md4.py +10 -0
  27. fast_cryptography/algorithms/hashes/md5.py +8 -0
  28. fast_cryptography/algorithms/hashes/ripemd160.py +12 -0
  29. fast_cryptography/algorithms/hashes/sha1.py +8 -0
  30. fast_cryptography/algorithms/hashes/sha224.py +9 -0
  31. fast_cryptography/algorithms/hashes/sha256.py +9 -0
  32. fast_cryptography/algorithms/hashes/sha384.py +8 -0
  33. fast_cryptography/algorithms/hashes/sha3_224.py +7 -0
  34. fast_cryptography/algorithms/hashes/sha3_256.py +7 -0
  35. fast_cryptography/algorithms/hashes/sha3_384.py +9 -0
  36. fast_cryptography/algorithms/hashes/sha3_512.py +9 -0
  37. fast_cryptography/algorithms/hashes/sha512.py +7 -0
  38. fast_cryptography/algorithms/scripts/__init__.py +5 -0
  39. fast_cryptography/algorithms/scripts/password.py +36 -0
  40. fast_cryptography/algorithms/scripts/what_encoding.py +67 -0
  41. fast_cryptography/algorithms/symmetric/__init__.py +9 -0
  42. fast_cryptography/algorithms/symmetric/aes.py +48 -0
  43. fast_cryptography/algorithms/symmetric/chacha20.py +38 -0
  44. fast_cryptography/algorithms/symmetric/fernet.py +19 -0
  45. fast_cryptography-0.1.0.dist-info/METADATA +1490 -0
  46. fast_cryptography-0.1.0.dist-info/RECORD +50 -0
  47. fast_cryptography-0.1.0.dist-info/WHEEL +5 -0
  48. fast_cryptography-0.1.0.dist-info/licenses/LICENSE +201 -0
  49. fast_cryptography-0.1.0.dist-info/licenses/NOTICE +25 -0
  50. fast_cryptography-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,81 @@
1
+ from .algorithms.asymmetric.rsa import gen_keys_pem as rsa_gen_keys_pem, encrypt as rsa_encrypt, decrypt as rsa_decrypt
2
+ from .algorithms.asymmetric.ecc import gen_keys_pem as ecc_gen_keys_pem, sign as ecc_sign, verify as ecc_verify
3
+ from .algorithms.asymmetric.ed25519 import gen_keys_pem as ed25519_gen_keys_pem, sign as ed25519_sign, verify as ed25519_verify
4
+
5
+ from .algorithms.symmetric.fernet import generate_key as fernet_generate_key, encrypt as fernet_encrypt, decrypt as fernet_decrypt
6
+ from .algorithms.symmetric.aes import generate_key as aes_generate_key, encrypt as aes_encrypt, decrypt as aes_decrypt
7
+ from .algorithms.symmetric.chacha20 import generate_key as chacha20_generate_key, encrypt as chacha20_encrypt, decrypt as chacha20_decrypt
8
+
9
+
10
+
11
+ from .algorithms.encoding.base64 import encode as base64_encode, decode as base64_decode, is_valid as is_valid_base64, url_encode as base64_url_encode, url_decode as base64_url_decode
12
+ from .algorithms.encoding.base58 import encode as base58_encode, decode as base58_decode, is_valid as is_valid_base58
13
+ from .algorithms.encoding.base16 import encode as base16_encode, decode as base16_decode, is_valid as is_valid_base16
14
+ from .algorithms.encoding.base32 import encode as base32_encode, decode as base32_decode, is_valid as is_valid_base32
15
+ from .algorithms.encoding.base85 import encode as base85_encode, decode as base85_decode, is_valid as is_valid_base85
16
+ from .algorithms.encoding.baseA85 import encode as baseA85_encode, decode as baseA85_decode, is_valid as is_valid_baseA85
17
+ from .algorithms.encoding.base45 import encode as base45_encode, decode as base45_decode, is_valid as is_valid_base45
18
+ from .algorithms.scripts.password import auth, verify
19
+ from .algorithms.scripts.what_encoding import what_encoding
20
+
21
+ from algorithms.hashes.md4 import hash_md4
22
+ from algorithms.hashes.md5 import hash_md5
23
+ from algorithms.hashes.ripemd160 import hash_ripemd160
24
+ from algorithms.hashes.sha1 import hash_sha1
25
+ from algorithms.hashes.sha224 import hash_sha224
26
+ from algorithms.hashes.sha256 import hash_sha256
27
+ from algorithms.hashes.sha384 import hash_sha384
28
+ from algorithms.hashes.sha512 import hash_sha512
29
+ from algorithms.hashes.sha3_224 import hash_sha3_224
30
+ from algorithms.hashes.sha3_256 import hash_sha3_256
31
+ from algorithms.hashes.sha3_384 import hash_sha3_384
32
+ from algorithms.hashes.sha3_512 import hash_sha3_512
33
+ from algorithms.hashes.blake2b import hash_blake2b
34
+ from algorithms.hashes.blake2s import hash_blake2s
35
+
36
+ from .algorithms.cryptorandom.byte import bytes_token, bytes_urandom, bytes_uuid, bytes_random
37
+ from .algorithms.cryptorandom.hex_bytes import hex_token, hex_token_bytes, encode_hex, decode_hex, hex2text, text2hex, is_valid_hex
38
+ from algorithms.cryptorandom.choice import crypto_choice, random_choice, random_choices, scientific_choice
39
+ from algorithms.cryptorandom.randint import crypto_randbelow, crypto_randint, random_randint
40
+ from algorithms.cryptorandom.salt import salt_gen, salt_gen_hex
41
+ from algorithms.cryptorandom.nonce import nonce_gen, nonce_gen_hex
42
+ from algorithms.cryptorandom.iv import iv_gen, iv_gen_hex
43
+
44
+ __all__ = [
45
+ # Asymmetric
46
+ 'rsa_gen_keys_pem', 'rsa_encrypt', 'rsa_decrypt',
47
+ 'ecc_gen_keys_pem', 'ecc_sign', 'ecc_verify',
48
+ 'ed25519_gen_keys_pem', 'ed25519_sign', 'ed25519_verify',
49
+
50
+ # Symmetric
51
+ 'fernet_generate_key', 'fernet_encrypt', 'fernet_decrypt',
52
+ 'aes_generate_key', 'aes_encrypt', 'aes_decrypt',
53
+ 'chacha20_generate_key', 'chacha20_encrypt', 'chacha20_decrypt',
54
+
55
+ # Encodings
56
+ 'base64_encode', 'base64_decode', 'is_valid_base64', 'base64_url_encode', 'base64_url_decode',
57
+ 'base58_encode', 'base58_decode', 'is_valid_base58',
58
+ 'base16_encode', 'base16_decode', 'is_valid_base16',
59
+ 'base32_encode', 'base32_decode', 'is_valid_base32',
60
+ 'base85_encode', 'base85_decode', 'is_valid_base85',
61
+ 'baseA85_encode', 'baseA85_decode', 'is_valid_baseA85',
62
+
63
+ # Password
64
+ 'auth', 'verify',
65
+
66
+ # Hashes
67
+ 'hash_md4', 'hash_md5', 'hash_ripemd160',
68
+ 'hash_sha1', 'hash_sha224', 'hash_sha256', 'hash_sha384', 'hash_sha512',
69
+ 'hash_sha3_224', 'hash_sha3_256', 'hash_sha3_384', 'hash_sha3_512',
70
+ 'hash_blake2b', 'hash_blake2s',
71
+
72
+ # Cryptorandom
73
+ 'bytes_token', 'bytes_urandom', 'bytes_uuid', 'bytes_random',
74
+ 'hex_token', 'hex_token_bytes', 'encode_hex', 'decode_hex',
75
+ 'hex2text', 'text2hex', 'is_valid_hex',
76
+ 'crypto_choice', 'random_choice', 'random_choices', 'scientific_choice',
77
+ 'crypto_randbelow', 'crypto_randint', 'random_randint',
78
+ 'salt_gen', 'salt_gen_hex',
79
+ 'nonce_gen', 'nonce_gen_hex',
80
+ 'iv_gen', 'iv_gen_hex'
81
+ ]
@@ -0,0 +1 @@
1
+ from . import asymmetric, symmetric, cryptorandom, scripts, encoding, hashes
@@ -0,0 +1,19 @@
1
+ from .rsa import gen_keys_pem as rsa_gen_keys_pem
2
+ from .rsa import encrypt as rsa_encrypt
3
+ from .rsa import decrypt as rsa_decrypt
4
+ from .ecc import gen_keys_pem as ecc_gen_keys_pem
5
+ from .ecc import sign as ecc_sign
6
+ from .ecc import verify as ecc_verify
7
+ from .ed25519 import gen_keys_pem as ed25519_gen_keys_pem
8
+ from .ed25519 import sign as ed25519_sign
9
+ from .ed25519 import verify as ed25519_verify
10
+
11
+ from .rsa import gen_keys_pem as rsa_gen_keys_pem, encrypt as rsa_encrypt, decrypt as rsa_decrypt
12
+ from .ecc import gen_keys_pem as ecc_gen_keys_pem, sign as ecc_sign, verify as ecc_verify
13
+ from .ed25519 import gen_keys_pem as ed25519_gen_keys_pem, sign as ed25519_sign, verify as ed25519_verify
14
+
15
+ __all__ = [
16
+ 'rsa_gen_keys_pem', 'rsa_encrypt', 'rsa_decrypt',
17
+ 'ecc_gen_keys_pem', 'ecc_sign', 'ecc_verify',
18
+ 'ed25519_gen_keys_pem', 'ed25519_sign', 'ed25519_verify'
19
+ ]
@@ -0,0 +1,55 @@
1
+ from cryptography.hazmat.primitives.asymmetric import ec
2
+ from cryptography.hazmat.primitives import serialization, hashes
3
+ import base64
4
+
5
+
6
+ def gen_keys_pem() -> dict:
7
+ """Generates an ECC key pair (secp256k1) in PEM format"""
8
+ private_key = ec.generate_private_key(ec.SECP256K1())
9
+ public_key = private_key.public_key()
10
+
11
+ private_pem = private_key.private_bytes(
12
+ encoding=serialization.Encoding.PEM,
13
+ format=serialization.PrivateFormat.PKCS8,
14
+ encryption_algorithm=serialization.NoEncryption()
15
+ ).decode('utf-8')
16
+
17
+ public_pem = public_key.public_bytes(
18
+ encoding=serialization.Encoding.PEM,
19
+ format=serialization.PublicFormat.SubjectPublicKeyInfo
20
+ ).decode('utf-8')
21
+
22
+ return {
23
+ 'private': private_pem,
24
+ 'public': public_pem
25
+ }
26
+
27
+
28
+ def sign(message: str, private_key_pem: str) -> str:
29
+ """Signs a message using ECC private key"""
30
+ private_key = serialization.load_pem_private_key(
31
+ private_key_pem.encode(),
32
+ password=None
33
+ )
34
+
35
+ signature = private_key.sign(
36
+ message.encode(),
37
+ ec.ECDSA(hashes.SHA256())
38
+ )
39
+ return base64.b64encode(signature).decode('utf-8')
40
+
41
+
42
+ def verify(message: str, signature_b64: str, public_key_pem: str) -> bool:
43
+ """Verifies an ECC signature using public key"""
44
+ public_key = serialization.load_pem_public_key(public_key_pem.encode())
45
+ signature = base64.b64decode(signature_b64)
46
+
47
+ try:
48
+ public_key.verify(
49
+ signature,
50
+ message.encode('utf-8'),
51
+ ec.ECDSA(hashes.SHA256())
52
+ )
53
+ return True
54
+ except:
55
+ return False
@@ -0,0 +1,58 @@
1
+ from cryptography.hazmat.primitives.asymmetric import ed25519
2
+ from cryptography.hazmat.primitives import serialization
3
+ import base64
4
+
5
+
6
+ def gen_keys_pem() -> dict:
7
+ """Generates an Ed25519 key pair in PEM format"""
8
+ private_key = ed25519.Ed25519PrivateKey()
9
+ public_key = private_key.public_key()
10
+
11
+ private_pem = private_key.private_bytes(
12
+ encoding=serialization.Encoding.PEM,
13
+ format=serialization.PrivateFormat.PKCS8,
14
+ encryption_algorithm=serialization.NoEncryption()
15
+ ).decode('utf-8')
16
+
17
+ public_pem = public_key.public_bytes(
18
+ encoding=serialization.Encoding.PEM,
19
+ format=serialization.PublicFormat.SubjectPublicKeyInfo
20
+ ).decode('utf-8')
21
+
22
+ return {
23
+ 'private':private_pem,
24
+ 'public':public_pem
25
+ }
26
+
27
+
28
+
29
+
30
+ def sign(message: str, private_key_pem: str) -> str:
31
+ """Signs a message using Ed25519 private key"""
32
+ private_key = serialization.load_pem_private_key(
33
+ private_key_pem.encode(),
34
+ password=None
35
+ )
36
+
37
+ signature = private_key.sign(
38
+ message.encode('utf-8')
39
+ )
40
+ return base64.b64encode(signature).decode('utf-8')
41
+
42
+ def verify(message: str, signature_b64: str, public_key_pem: str) -> bool:
43
+ """Verifies an Ed25519 signature using public key"""
44
+ public_key = serialization.load_pem_public_key(public_key_pem)
45
+ signature = base64.b64decode(signature_b64)
46
+
47
+ try:
48
+ public_key.verify(
49
+ signature,
50
+ message.encode('utf-8')
51
+ )
52
+
53
+ return True
54
+
55
+ except:
56
+ return False
57
+
58
+
@@ -0,0 +1,59 @@
1
+ from cryptography.hazmat.primitives.asymmetric import rsa, padding
2
+ from cryptography.hazmat.primitives import serialization, hashes
3
+ import base64
4
+
5
+ def gen_keys_pem(key_size=2048) -> dict:
6
+ """Generates an RSA key pair in PEM format"""
7
+ private_key = rsa.generate_private_key(
8
+ public_exponent=65537,
9
+ key_size=key_size
10
+ )
11
+ public_key = private_key.public_key()
12
+
13
+ private_pem = private_key.private_bytes(
14
+ encoding=serialization.Encoding.PEM,
15
+ format=serialization.PrivateFormat.PKCS8,
16
+ encryption_algorithm=serialization.NoEncryption()
17
+ ).decode('utf-8')
18
+
19
+ public_pem = public_key.public_bytes(
20
+ encoding=serialization.Encoding.PEM,
21
+ format=serialization.PublicFormat.SubjectPublicKeyInfo
22
+ ).decode('utf-8')
23
+
24
+ return {
25
+ 'private': private_pem,
26
+ 'public': public_pem
27
+ }
28
+
29
+ def encrypt(message: str, public_pem: str) -> str:
30
+ """Encrypts a message using an RSA public key"""
31
+ public_key = serialization.load_pem_public_key(public_pem.encode())
32
+
33
+ encrypted = public_key.encrypt(
34
+ message.encode(),
35
+ padding.OAEP(
36
+ mgf=padding.MGF1(algorithm=hashes.SHA256()),
37
+ algorithm=hashes.SHA256(),
38
+ label=None
39
+ )
40
+ )
41
+ return base64.b64encode(encrypted).decode()
42
+
43
+ def decrypt(encrypted_b64: str, private_key_pem: str) -> str:
44
+ """Decrypts a message using an RSA private key"""
45
+ private_key = serialization.load_pem_private_key(
46
+ private_key_pem.encode(),
47
+ password=None
48
+ )
49
+
50
+ encrypted = base64.b64decode(encrypted_b64)
51
+ decrypted = private_key.decrypt(
52
+ encrypted,
53
+ padding.OAEP(
54
+ mgf=padding.MGF1(algorithm=hashes.SHA256()),
55
+ algorithm=hashes.SHA256(),
56
+ label=None
57
+ )
58
+ )
59
+ return decrypted.decode()
@@ -0,0 +1,17 @@
1
+ from .byte import bytes_token, bytes_urandom, bytes_uuid, bytes_random
2
+ from .hex_bytes import hex_token, hex_token_bytes, encode_hex, decode_hex, hex2text, text2hex, is_valid_hex
3
+ from .salt import salt_gen, salt_gen_hex
4
+ from .nonce import nonce_gen, nonce_gen_hex
5
+ from .iv import iv_gen, iv_gen_hex
6
+ from .choice import crypto_choice, random_choice, random_choices, scientific_choice
7
+ from .randint import crypto_randbelow, crypto_randint, random_randint
8
+
9
+ __all__ = [
10
+ 'bytes_token', 'bytes_urandom', 'bytes_uuid', 'bytes_random',
11
+ 'hex_token', 'hex_token_bytes', 'encode_hex', 'decode_hex', 'hex2text', 'text2hex', 'is_valid_hex',
12
+ 'salt_gen', 'salt_gen_hex',
13
+ 'nonce_gen', 'nonce_gen_hex',
14
+ 'iv_gen', 'iv_gen_hex',
15
+ 'crypto_choice', 'random_choice', 'random_choices', 'scientific_choice',
16
+ 'crypto_randbelow', 'crypto_randint', 'random_randint'
17
+ ]
@@ -0,0 +1,20 @@
1
+ import secrets
2
+ import os
3
+ import random
4
+ import uuid
5
+
6
+ def bytes_token(byte: int) -> bytes:
7
+ """Generate bytes using secrets (safe)"""
8
+ return secrets.token_bytes(byte)
9
+
10
+ def bytes_urandom(byte: int) -> bytes:
11
+ """Generate bytes using os.urandom (safe)"""
12
+ return os.urandom(byte)
13
+
14
+ def bytes_uuid() -> bytes:
15
+ """Generate 16 bytes using uuid (medium security)"""
16
+ return uuid.uuid4().bytes
17
+
18
+ def bytes_random(byte: int) -> bytes:
19
+ """Generate bytes using random (NOT SAFE for crypto!)"""
20
+ return random.randbytes(byte)
@@ -0,0 +1,21 @@
1
+ import secrets
2
+ import random
3
+ import numpy as np
4
+
5
+ def crypto_choice(choicen) -> str:
6
+ """Cryptographically secure random choice"""
7
+ return secrets.choice(choicen)
8
+
9
+ def random_choice(choicen) -> str:
10
+ """Not secure random choice"""
11
+ return random.choice(choicen)
12
+
13
+ def random_choices(choicen) -> str:
14
+ """Not secure random choices"""
15
+ return random.choices(choicen)
16
+
17
+ def scientific_choice(choicen) -> str:
18
+ """Scientific random choice"""
19
+ return np.random.choice(choicen)
20
+
21
+
@@ -0,0 +1,34 @@
1
+ import secrets
2
+ import binascii
3
+
4
+ def hex_token(byte: int) -> str:
5
+ """Generate hex string using secrets (safe)"""
6
+ return secrets.token_hex(byte)
7
+
8
+ def hex_token_bytes(byte: int) -> str:
9
+ """Generate hex string via bytes using secrets (safe)"""
10
+ return secrets.token_bytes(byte).hex()
11
+
12
+ def encode_hex(data: bytes) -> str:
13
+ """Encode bytes to hex string"""
14
+ return binascii.hexlify(data).decode('utf-8')
15
+
16
+ def decode_hex(hex_str: str) -> bytes:
17
+ """Decode hex string to bytes"""
18
+ return binascii.unhexlify(hex_str)
19
+
20
+ def hex2text(hex_str: str) -> str:
21
+ """Convert hex string to text (UTF-8)"""
22
+ return decode_hex(hex_str).decode('utf-8', errors='replace')
23
+
24
+ def text2hex(text: str) -> str:
25
+ """Convert text to hex string"""
26
+ return encode_hex(text.encode('utf-8'))
27
+
28
+ def is_valid_hex(hex_str: str) -> bool:
29
+ """Check if string is valid hex"""
30
+ try:
31
+ bytes.fromhex(hex_str)
32
+ return True
33
+ except (binascii.Error, ValueError):
34
+ return False
@@ -0,0 +1,12 @@
1
+ import secrets
2
+
3
+ def iv_gen(byte: 16) -> bytes:
4
+ """Generator iv using module secrets
5
+ Bytes 16"""
6
+ return secrets.token_bytes(byte)
7
+
8
+ def iv_gen_hex() -> str:
9
+ """Generator iv bytes to hex using module secrets
10
+ Bytes 16"""
11
+ return iv_gen().hex()
12
+
@@ -0,0 +1,9 @@
1
+ import secrets
2
+
3
+ def nonce_gen(byte: int = 16) -> bytes:
4
+ """Generate nonce bytes (12-16 bytes recommended)"""
5
+ return secrets.token_bytes(byte)
6
+
7
+ def nonce_gen_hex(byte: int = 16) -> str:
8
+ """Generate nonce as hex string"""
9
+ return secrets.token_hex(byte)
@@ -0,0 +1,19 @@
1
+ import random
2
+ import secrets
3
+
4
+ def crypto_randbelow(number: int) -> int:
5
+ """Return random integer in range (0, n)"""
6
+ return secrets.randbelow(number)
7
+
8
+ def crypto_randint(a: int, b: int) -> int:
9
+ """Return random integer in range [a, b] inclusive"""
10
+ return secrets.randbelow(b - a + 1) + a
11
+
12
+ def random_randint(a: int, b: int) -> int:
13
+ """Return random integer in range (0 , n)
14
+ It's not safe"""
15
+ return random.randint(a, b)
16
+
17
+
18
+
19
+
@@ -0,0 +1,11 @@
1
+ import secrets
2
+
3
+ def salt_gen(byte: int) -> bytes:
4
+ """Generator salt using module secrets
5
+ Bytes 16-64"""
6
+ return secrets.token_bytes(byte)
7
+
8
+ def salt_gen_hex() -> str:
9
+ """Generator salt bytes to hex using module secrets
10
+ Bytes 16-64"""
11
+ return salt_gen().hex()
@@ -0,0 +1,17 @@
1
+ from .base64 import encode as base64_encode, decode as base64_decode, url_encode as base64_url_encode, url_decode as base64_url_decode, is_valid as is_valid_base64
2
+ from .base58 import encode as base58_encode, decode as base58_decode, is_valid as is_valid_base58
3
+ from .base32 import encode as base32_encode, decode as base32_decode, is_valid as is_valid_base32
4
+ from .base16 import encode as base16_encode, decode as base16_decode, is_valid as is_valid_base16
5
+ from .base85 import encode as base85_encode, decode as base85_decode, is_valid as is_valid_base85
6
+ from .baseA85 import encode as baseA85_encode, decode as baseA85_decode, is_valid as is_valid_baseA85
7
+ from .base45 import encode as base45_encode, decode as base45_decode, is_valid as is_valid_base45
8
+
9
+ __all__ = [
10
+ 'base64_encode', 'base64_decode', 'base64_url_encode', 'base64_url_decode', 'is_valid_base64',
11
+ 'base58_encode', 'base58_decode', 'is_valid_base58',
12
+ 'base32_encode', 'base32_decode', 'is_valid_base32',
13
+ 'base16_encode', 'base16_decode', 'is_valid_base16',
14
+ 'base85_encode', 'base85_decode', 'is_valid_base85',
15
+ 'baseA85_encode', 'baseA85_decode', 'is_valid_baseA85',
16
+ 'base45_encode', 'base45_decode', 'is_valid_base45'
17
+ ]
@@ -0,0 +1,17 @@
1
+ import base64 as b64
2
+
3
+ def encode(data: bytes) -> str:
4
+ """Encode using module base64 for base16"""
5
+ b64.b16encode(data).decode()
6
+
7
+ def decode(data: str) -> bytes:
8
+ """Decode using module base54 for base16"""
9
+ b64.b16decode(data)
10
+
11
+ def is_valid(data: str) -> bool:
12
+ """Check if string is base64 for base16"""
13
+ try:
14
+ bytes.fromhex(data)
15
+ return True
16
+ except:
17
+ return False
@@ -0,0 +1,17 @@
1
+ import base64 as b64
2
+
3
+ def encode(data: bytes) -> str:
4
+ """Encode using module base64 for base32"""
5
+ return b64.b32encode(data).decode()
6
+
7
+ def decode(data: str) -> bytes:
8
+ """Decode using module base64 for base32"""
9
+ return b64.b32decode(data)
10
+
11
+ def is_valid(data: str) -> bool:
12
+ """Check if string is base64 fror base32"""
13
+ try:
14
+ bytes.fromhex(data)
15
+ return True
16
+ except:
17
+ return False
@@ -0,0 +1,20 @@
1
+ import base45
2
+
3
+
4
+ def encode(data: bytes) -> str:
5
+ """Encode bytes to Base45 string"""
6
+ return base45.b45encode(data).decode()
7
+
8
+
9
+ def decode(s: str) -> bytes:
10
+ """Decode Base45 string to bytes"""
11
+ return base45.b45decode(s)
12
+
13
+
14
+ def is_valid(s: str) -> bool:
15
+ """Check if string is valid Base45"""
16
+ try:
17
+ bytes.fromhex(s)
18
+ return True
19
+ except Exception:
20
+ return False
@@ -0,0 +1,17 @@
1
+ import base58 as b58
2
+
3
+ def encode(data: bytes) -> str:
4
+ """Encode using module base58"""
5
+ return b58.b58encode(data).decode()
6
+
7
+ def decode(data: str) -> bytes:
8
+ """Decode using module base58"""
9
+ return b58.b58decode(data)
10
+
11
+ def is_valid(data: str) -> bool:
12
+ """Check if string is base58"""
13
+ try:
14
+ bytes.fromhex(data)
15
+ return True
16
+ except:
17
+ return False
@@ -0,0 +1,26 @@
1
+ import base64 as b64
2
+
3
+ def encode(data: bytes) -> str:
4
+ """Encode using module base64"""
5
+ return b64.b64encode(data).decode()
6
+
7
+ def decode(data: str) -> bytes:
8
+ """Decode using module base64"""
9
+ return b64.b64decode(data)
10
+
11
+ def url_encode(data: bytes) -> str:
12
+ """Encode url using module base64"""
13
+ return b64.urlsafe_b64encode(data).decode()
14
+
15
+ def url_decode(data: str) -> bytes:
16
+ """Decode url using module base64"""
17
+ return b64.urlsafe_b64decode(data)
18
+
19
+ def is_valid(data: str) -> bool:
20
+ """Check if string is base64"""
21
+ try:
22
+ bytes.fromhex(data)
23
+ return True
24
+ except:
25
+ return False
26
+
@@ -0,0 +1,17 @@
1
+ import base64 as b64
2
+
3
+ def encode(data: bytes) -> str:
4
+ """Encode using module base64 for base85"""
5
+ return b64.b85encode(data).decode()
6
+
7
+ def decode(data: str) -> bytes:
8
+ """Decode using module base64 for base85"""
9
+ return b64.b85decode(data)
10
+
11
+ def is_valid(data: str) -> bool:
12
+ """Check if string is base64 for base85"""
13
+ try:
14
+ bytes.fromhex(data)
15
+ return True
16
+ except:
17
+ return False
@@ -0,0 +1,17 @@
1
+ import base64 as b64
2
+
3
+ def encode(data: bytes) -> str:
4
+ """Encode using module base64 for baseA85"""
5
+ return b64.a85encode(data).decode()
6
+
7
+ def decode(data: str) -> bytes:
8
+ """Decode using module base64 from baseA85"""
9
+ return b64.a85decode(data)
10
+
11
+ def is_valid(data: str) -> bool:
12
+ """Check if string is base64 for baseA85"""
13
+ try:
14
+ bytes.fromhex(data)
15
+ return True
16
+ except:
17
+ return False
@@ -0,0 +1,21 @@
1
+ from .sha256 import hash_sha256
2
+ from .sha512 import hash_sha512
3
+ from .sha384 import hash_sha384
4
+ from .sha224 import hash_sha224
5
+ from .sha1 import hash_sha1
6
+ from .sha3_256 import hash_sha3_256
7
+ from .sha3_512 import hash_sha3_512
8
+ from .sha3_384 import hash_sha3_384
9
+ from .sha3_224 import hash_sha3_224
10
+ from .blake2b import hash_blake2b
11
+ from .blake2s import hash_blake2s
12
+ from .md5 import hash_md5
13
+ from .md4 import hash_md4
14
+ from .ripemd160 import hash_ripemd160
15
+
16
+ __all__ = [
17
+ 'hash_sha256', 'hash_sha512', 'hash_sha384', 'hash_sha224', 'hash_sha1',
18
+ 'hash_sha3_256', 'hash_sha3_512', 'hash_sha3_384', 'hash_sha3_224',
19
+ 'hash_blake2b', 'hash_blake2s',
20
+ 'hash_md5', 'hash_md4', 'hash_ripemd160'
21
+ ]
@@ -0,0 +1,8 @@
1
+ import secrets
2
+ import hashlib
3
+
4
+ def hash_blake2b(message: str, byte: int) -> str:
5
+ """Blake2b Hash Function"""
6
+ salt = secrets.token_bytes(byte)
7
+ return hashlib.blake2b(message + salt.encode()).hexdigest()
8
+
@@ -0,0 +1,9 @@
1
+ import secrets
2
+ import hashlib
3
+
4
+ def hash_blake2s(message: str, byte: int) -> str:
5
+ """Blake2s Hash Function"""
6
+ salt = secrets.token_bytes(byte)
7
+ return hashlib.blake2s(message + salt.encode()).hexdigest()
8
+
9
+
@@ -0,0 +1,10 @@
1
+ from Crypto.Hash import MD4
2
+ import secrets
3
+
4
+ def hash_md4(message: str, byte: int) -> str:
5
+ """MD4 Hash Function"""
6
+ salt = secrets.token_bytes(byte)
7
+ hash_obj = MD4.new()
8
+ hash_obj.update(salt + message.encode())
9
+ hash_result = hash_obj.hexdigest()
10
+ return hash_result
@@ -0,0 +1,8 @@
1
+ import hashlib
2
+ import secrets
3
+
4
+ def hash_md5(message: str, byte: int) -> str:
5
+ """MD5 Hash Function"""
6
+ salt = secrets.token_bytes(byte)
7
+ return hashlib.md5(message + salt.encode()).hexdigest()
8
+