Add WIP. Likely going nowhere.

I've thrashed around a bit, I think I'll move to rust.
This commit is contained in:
Eli Ribble 2023-11-10 15:51:13 -07:00
parent 0f450672b1
commit e1e6684196
2 changed files with 37 additions and 0 deletions

View File

@ -25,6 +25,7 @@ def box():
with open(args.message, "rb") as f:
data = f.read()
shared_ecc_key, ciphered_public_key = _generate_encryption_key(certificate.public_key())
aad = b"authenticated but unencrypted data"
key = aead.ChaCha20Poly1305.generate_key()
with open("encryption.key", "wb") as f:
@ -41,6 +42,15 @@ def box():
print(f"Wrote encrypted message to '{args.output}'")
def ecc_calc_encryption_keys(pubKey):
ciphertextPrivKey = secrets.randbelow(curve.field.n)
ciphertextPubKey = ciphertextPrivKey * curve.g
sharedECCKey = pubKey * ciphertextPrivKey
return (sharedECCKey, ciphertextPubKey)
def ecc_calc_decryption_key(privKey, ciphertextPubKey):
sharedECCKey = ciphertextPubKey * privKey
return sharedECCKey
def generate():
print("Please name this aegis. You can call it anything. Frequently people use their legal name.")

27
gongor/cipher.py Normal file
View File

@ -0,0 +1,27 @@
import argparse
from pathlib import Path
from cryptography import x509
from cryptography.hazmat.primitives import serialization
def box_message():
parser = argparse.ArgumentParser()
parser.add_argument("recipient_certificate", type=Path, help="Path to the certificate of the recipient")
parser.add_argument("sender_key", type=Path, help="Path to the private key of the sender")
parser.add_argument("--sender-key-password", type="str", default=None, help="The password to the sender private key")
parser.add_argument("message", type=Path, help="Path to the message to box")
args = parser.parse_args()
recipient_cert = _load_certificate(args.recipient_certificate)
sender_key = _load_key(args.sender_key)
def _load_certificate(path: Path) -> x509.Certificate:
with open(path, "rb") as f:
return x509.load_pem_x509_certificate(f.read())
def _load_key(path: Path, password: str) -> EllipticCurvePrivateKey:
with open(path, "rb") as f:
return serialization.load_pem_private_key(f.read(), password)