This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Date : 17 - 08 - 2022 | |
# Ref: RTFM v2 | |
''' | |
Python3 simple-https-server.py | |
''' | |
import http.server, ssl, socketserver | |
context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER) | |
context.load_cert_chain("cert.pem") # PUT YOUR cert.pem HERE |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import hashlib | |
import time | |
LOG = 'log.txt' | |
# function area | |
# ------------------------------------------------------------- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess as sp | |
import os | |
# check if folder "ca-cert" exists | |
# if not, create it | |
# if yes, delete it | |
if os.path.exists("ca-cert"): | |
sp.call(["rm", "-rf", "ca-cert"]) | |
sp.call(["mkdir", "ca-cert"]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess as sp | |
import os | |
# check ca-cert/ca.crt and ca-cert/ca.key | |
if os.path.exists("ca-cert/ca.crt") and os.path.exists("ca-cert/ca.key"): | |
print ("CA is ready") | |
else: | |
print("CA is not ready, generate it first") | |
print("Run generate-ca.py") | |
exit() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tkinter as tk | |
def countdown(count): | |
# change text in label | |
# count = '01:30:00' | |
hour, minute, second = count.split(':') | |
hour = int(hour) | |
minute = int(minute) | |
second = int(second) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import base64 | |
import os | |
from pathlib import Path | |
from Crypto.PublicKey import RSA | |
from Crypto.Cipher import PKCS1_OAEP, AES | |
# public key with base64 encoding | |
pubKey = '''LS0tLS1CRUdJTiBQVUJMSUMgS0VZLS0tLS0KTUlJQklqQU5CZ2txaGtpRzl3MEJBUUVGQUFPQ0FROEFNSUlCQ2dLQ0FRRUFxZUs0TkppUGlaQ1o0aDRwM2lzNwpyOTdTRGRnaWtrckswNE1sc3oraHY2UmIxKzB2M1hsY296QXVGeGIvMjkxTE5tNGs1M1RZTXQ4M3BPRm9ZRTh4Ckx0VE55UVNSMDR2dzBGcGRwU3Y1YVVjbysxRmtwRjRMdCtqV1Q0YjVrTUFqWTRkOW5Yb3lRQmxJbzBWckMwQzIKcldpeklONGV1TXBTbll3V2Z0a2JsZE5qcDJ1U0hFeWM1Z0FZR1ZKSWZ6TVRiaUxZd0k5aU9rNllnWEozbWJLdAp1dHo2WlRTdlplVzEwaUhrc2JXUXgvcUVjR0JLWFJUbkUvYTJkZVhvRThRaFZOTUV5Z0xVQmF3NERYaWRCbXBiCnFmSWtvZk5UWlQ3K2NyaENocVptYmFrSjA5bTdmT3k1TURud0oraU0wdlBheW1tdGduWnBrR0NQNlpDVDlkeHoKcHdJREFRQUIKLS0tLS1FTkQgUFVCTElDIEtFWS0tLS0t''' | |
pubKey = base64.b64decode(pubKey) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import base64 | |
import os | |
from Crypto.PublicKey import RSA | |
from Crypto.Cipher import PKCS1_OAEP, AES | |
''' | |
with open('public.pem', 'rb') as f: | |
public = f.read() | |
print(base64.b64encode(public)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def decrypt(dataFile, privateKeyFile): | |
''' | |
use EAX mode to allow detection of unauthorized modifications | |
''' | |
# read private key from file | |
with open(privateKeyFile, 'rb') as f: | |
privateKey = f.read() | |
# create private key object | |
key = RSA.import_key(privateKey) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def encrypt(dataFile, publicKeyFile): | |
''' | |
use EAX mode to allow detection of unauthorized modifications | |
''' | |
# read data from file | |
with open(dataFile, 'rb') as f: | |
data = f.read() | |
# convert data to bytes | |
data = bytes(data) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
pip install pycryptodome | |
''' | |
from Crypto.PublicKey import RSA | |
key = RSA.generate(2048) | |
privateKey = key.export_key() | |
publicKey = key.publickey().export_key() |
NewerOlder