Skip to content

This Repository is a collection of different ethical hacking tools and malware's for penetration testing and research purpose written in python, ruby, rust, c++, go and c.

Create encrypt_decrypt_AES.py

Abdul Wahab Junaid80310a4be9dc
diff --git a/Cryptography/encrypt_decrypt_AES.py b/Cryptography/encrypt_decrypt_AES.py
new file mode 100644
index 0000000..dff6851
--- /dev/null
+++ b/Cryptography/encrypt_decrypt_AES.py
@@ -0,0 +1,20 @@
+import os
+from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
+from cryptography.hazmat.backends import default_backend
+
+backend = default_backend()
+key = os.urandom(32)
+iv = os.urandom(16)
+cipher = Cipher(algorithms.AES(key), modes.CBC(iv), backend=backend)
+
+encryptor = cipher.encryptor()
+print(encryptor)
+
+message_encrypted = encryptor.update("a secret message".encode("utf8"))
+
+print("Cipher text: "+str(message_encrypted))
+cipher_text = message_encrypted + encryptor.finalize()
+
+decryptor = cipher.decryptor()
+
+print("Plain text: "+str(decryptor.update(cipher_text).decode()))