You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fast-Cryptography - This is a library with cryptographic operations, including asymmetric and symmetric encryption, signatures, and hashes. We use modern cryptographic technologies!. This module was created for lazy developers.
fromfast_cryptography.algorithms.asymmetric.rsaimportrsa_gen_keys_pemkeys=rsa_gen_keys_pem() # We do not specify attributesprint(keys)
Now how it works rsa_encrypt();
Stages
Load public key
Encrypting
Print: encrypted message in the format Base64
And in code:
fromfast_cryptography.algorithms.asymmetric.rsaimportrsa_encrypt, rsa_gen_keys_pemkeys=rsa_gen_keys_pem()
public_pem=keys['public']
encryption=rsa_encrypt("Your message", public_pem) # Specify the message and your public key (preferably as a variable)print(encryption)
And at the end how it works rsa_decrypt():
Stages
Load private key
Decrypting
Print: message
And in code:
fromfast_cryptography.algorithms.asymmetric.rsaimportrsa_decrypt, rsa_gen_keys_pem, rsa_encryptkeys=rsa_gen_keys_pem()
private_pem=keys['private']
public_pem=keys['public']
encryption=rsa_encrypt("Your message", public_pem)
decryption=rsa_decrypt(encryption, private_pem) # Specify the encrypted message and your private key (preferably as a variable)print(decryption)
ECC
There are 3 functions in total: ecc_gen_keys_pem(), ecc_sign(), ecc_verify()
fromfast_cryptography.algorithms.asymmetric.eccimportecc_gen_keys_pemkeys=ecc_gen_keys_pem() # We do not specify attributesprint(keys)
Now how it works ecc_sign:
Stages
Load private key
Signing up
Print: signature in formate Base64
And in code:
fromfast_cryptography.algorithms.asymmetric.eccimportecc_gen_keys_pem, ecc_signkeys=ecc_gen_keys_pem()
private_pem=keys['private']
signature=ecc_sign("Your message", private_pem) # Specify the message and your private key (preferably as a variable)print(signature)
fromfast_cryptography.algorithms.asymmetric.ed25519imported25519_gen_keys_pemkeys=ed25519_gen_keys_pem() # We do not specify attributesprint(keys)
Now how it works ed25519_sign():
Stages
Load private key
Signing up
Print: signature in format Base64
And in code:
fromfast_cryptography.algorithms.asymmetric.ed25519imported25519_gen_keys_pem, ed25519_signkeys=ed25519_gen_keys_pem()
private_pem=keys['private']
signature=sign("Your message", private_pem) # Specify the message and your private key (preferably as a variable)
fromfast_cryptography.algorithms.symmetric.fernetimportfernet_generate_keykey=fernet_generate_key() # We do not specify attributesprint(key)
Now how it works fernet_encrypt():
Stages
Encode your key for cipher
Encrypting
Print: your encrypted message in UTF-8
And in code:
fromfast_cryptography.algorithms.symmetric.fernetfernet_generate_key, fernet_encryptkey=fernet_generate_key()
encrypt=fernet_encrypt("Your message", key) # Specify the message and your key (preferably as a variable)print(encrypt)
And at the end how it works fernet_decrypt():
Stages
Encode your key for cipher
Decrypting
Print: your decrypted message
And in code:
fromfast_cryptography.algorithms.symmetric.fernetimportfernet_generate_key, fernet_encrypt, fernet_decryptkey=fernet_generate_key()
encrypt=fernet_encrypt("Your message", key)
decrypted=fernet_decrypt(encrypt, key) # Specify the encrypted message and your key (preferably as a variable)
AES-CBC (without authentication)
There are 3 functions in total: aes_generate_key(), aes_encrypt(), aes_decrypt()
fromfast_cryptography.algorithms.symmetric.aes_cbcimportaes_generate_keysize=# 16 (AES-128), 24 (AES-192) or 32 (AES-256)key=aes_generate_key(size) # We do specify attribute key size (16, 24 or 32)print(key)
Now how it works aes_encrypt():
Stages
Encode message to bytes
Decode key from Base64
Generate random IV (16 bytes)
Create AES cipher in CBC mode with IV
Create PKCS7 padder (block size 16)
Pad the message
Encrypt padded message
Combine IV + ciphertext
Encode result to Base64
And in code:
fromfast_cryptography.algorithms.symmetric.aes_cbcimportaes_generate_key, aes_encryptsize=# 16 (AES-128), 24 (AES-192) or 32 (AES-256)key=aes_generate_key(size)
encrypt=aes_encrypt("Your message", key) # Specify the message and your key (preferably as a variable)print(encrypt)
And at the end how it works aes_decrypt():
Stages
Decode encrypted data from Base64
Decode key from Base64
Extract IV (first 16 bytes)
Extract ciphertext (remaining bytes)
Create AES cipher in CBC mode with IV
Decrypt ciphertext
Unpad decrypted data (PKCS7)
Decode bytes to string
And in code:
fromfast_cryptography.algorithms.symmetric.aes_cbcimportaes_generate_key, aes_encrypt, aes_decryptsize=# 16 (AES-128), 24 (AES-192) or 32 (AES-256)key=aes_generate_key(size)
encrypt=aes_encrypt("Your message", key)
decrypted=aes_decrypt(encrypted, key) # Specify the encrypted message and your key (preferably as a variable)
AES-GCM (with authentication)
There are 3 functions in total: aes_gcm_generate_key(), aes_gcm_encrypt(), aes_gcm_decrypt()
fromfast_cryptography.algorithms.symmetric.aes_gcmimportaes_gcm_generate_keysize=# 16 (AES-128), 24 (AES-192) or 32 (AES-256)key=aes_gcm_generate_key(size) # We do specify attribute key size (16, 24 or 32)print(key)
Now how it works aes_gcm_encrypt():
Stages
Encode message to bytes
Decode key from Base64
Generate random nonce (12 bytes)
Create AESGCM cipher with key
Encrypt message (authentication built-in)
Combine nonce + ciphertext
Encode result to Base64
And in code:
fromfast_cryptography.algorithms.symmetric.aes_gcmimportaes_generate_key, aes_encryptsize=128# or 256key=aes_generate_key(size)
encrypted=aes_encrypt("Your message", key)
print(encrypted)
And at the end how it works aes_decrypt():
Stages
Decode encrypted data from Base64
Decode key from Base64
Extract nonce (first 12 bytes)
Extract ciphertext (remaining bytes)
Create AESGCM cipher with key
Decrypt ciphertext (authentication verified)
Decode bytes to string
And in code:
fromfast_cryptography.algorithms.symmetric.aes_gcmimportaes_generate_key, aes_encrypt, aes_decryptsize=128# or 256key=aes_generate_key(size)
encrypted=aes_encrypt("Your message", key)
decrypted=aes_decrypt(encrypted, key)
ChaCha20-Poly1305
There are 3 functions in total: chacha20_poly1305_generate_key(), chacha20_poly1305_encrypt(), chacha20_poly1305_decrypt()
fromfast_cryptography.algorithms.symmetric.chacha20importchacha20_generate_key, chacha20_encryptkey=chacha20_generate_key()
encrypt=chacha20_encrypt("Your message", key) # Specify the message and your key (preferably as a variable)print(encrypt)
And at the end how it works chacha20_decrypt():
Stages
Decode encrypted data from Base64
Decode key from Base64
Extract nonce (first 16 bytes)
Extract ciphertext (remaining bytes)
Create ChaCha20 cipher with nonce
Decrypt ciphertext
Decode bytes to string
And in code:
fromfast_cryptography.algorithms.symmetric.chacha20importchacha20_generate_key, chacha20_encrypt, chacha20_decryptkey=chacha20_generate_key()
encrypt=chacha20_encrypt("Your message", key)
decrypted=chacha20_decrypt(encrypted, key) # Specify the encrypted message and your key (preferably as a variable)
Hashes
We are use the best hashes and the worst hashes in this libraly
Warning: For security use size salt: 32 Bytes. But can use 16-64 Bytes. GoodLuck!
fromfast_cryptography.algorithms.cryptorandom.byteimportbytes_token, bytes_urandom, bytes_uuid, bytes_randomprint(bytes_token(32)) # I'm use 32 bytes. But can you use 16-64 bytes. 32 bytes it's safeprint(bytes_urandom(32))
print(bytes_uuid(32))
print(bytes_random(32))
# WARNINGS!!! Don't forget to specify the quantity of bytes.
fromfast_cryptography.algorithms.cryptorandom.saltimportsalt_gen, salt_gen_hexprint(salt_gen(32)) # Don't forget to specify the quantity of bytes.print(salt_gen_hex(32))
fromfast_cryptography.algorithms.cryptorandom.nonceimportnonce_gen, nonce_gen_hexprint(nonce_gen()) # You can choose not to specify a size nonce (only 16), or you can specify (12-16)print(nonce_gen_hex())
fromfast_cryptography.algorithms.cryptorandom.nonceimportiv_gen, iv_gen_hexprint(iv_gen()) # You don't need to specify the size iv, size iv only 16 bytesprint(iv_gen_hex())
fromfast_cryptography.algorithms.cryptorandom.choiceimportcrypto_choice, random_choice, random_choices, scientific_choicechoice= ['1', '2'] # I'm showing you on the example, but you create mine# Warning: don't forget to specify the variable (choice for example)print(crypto_choice(choice))
print(random_choice(choice))
print(random_choices(choice))
print(scientific_choice(choice))
Selects a random (use cryptography) number from number 0 up to a number (selected by you)
Print: selected number
And how it works crypto_randint and random_randint:
| Stages |
| Selects a random (use cryptography or not) number (selected by you) up to a number (selected by you) |
| Print: selected number |
And in code:
fromfast_cryptography.algorithms.cryptorandom.randintimportcrypto_randbelow, crypto_randint, random_randintnumber_one=21# For example (variable for all function)number_two=1221# For example (variable for crypto_randint and random_randint)# Warning: don't forget to specify the variableprint(crypto_randbelow(number_one)) #print(crypto_randint(number_one, number_two))
print(random_randint(number_one, number_two))
Encoding
Here 7 modules: base64, base58, base45, base32, base16, base85, baseA85