mirror of
https://github.com/github/codeql.git
synced 2025-12-18 01:33:15 +01:00
This PR was rebased on newest main, but was written a long time ago when all the framework test-files were still in experimental. I have not re-written my local git-history, since there are MANY updates to those files (and I dare not risk it).
33 lines
1.1 KiB
Python
33 lines
1.1 KiB
Python
from cryptography.hazmat.primitives.ciphers import algorithms, Cipher
|
|
import os
|
|
|
|
key = os.urandom(256//8)
|
|
|
|
algorithm = algorithms.ARC4(key)
|
|
cipher = Cipher(algorithm, mode=None)
|
|
|
|
# ------------------------------------------------------------------------------
|
|
# encrypt/decrypt
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# following https://cryptography.io/en/latest/hazmat/primitives/symmetric-encryption.html#cryptography.hazmat.primitives.ciphers.algorithms.ARC4
|
|
|
|
print("encrypt/decrypt")
|
|
|
|
secret_message = b"secret message"
|
|
|
|
encryptor = cipher.encryptor()
|
|
encrypted = encryptor.update(secret_message) # $ CryptographicOperation CryptographicOperationAlgorithm=ARC4 CryptographicOperationInput=secret_message
|
|
encrypted += encryptor.finalize()
|
|
|
|
print("encrypted={}".format(encrypted))
|
|
|
|
print()
|
|
|
|
decryptor = cipher.decryptor()
|
|
decrypted = decryptor.update(encrypted) # $ CryptographicOperation CryptographicOperationAlgorithm=ARC4 CryptographicOperationInput=encrypted
|
|
decrypted += decryptor.finalize()
|
|
|
|
print("decrypted={}".format(decrypted))
|
|
assert decrypted == secret_message
|