diff options
| author | Gab <24553253+gabrix73@users.noreply.github.com> | 2025-03-08 14:59:35 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-08 14:59:35 +0100 |
| commit | 4a3ae9929f4657a0f2e9ccf393205655895bb501 (patch) | |
| tree | cc4e8089f178b791875a9a3b34f842cf7466ba4f /security/crypto.py | |
| parent | 489f247cffd1a63936a884c6d336b318179b39d8 (diff) | |
| download | securewhisper-4a3ae9929f4657a0f2e9ccf393205655895bb501.tar.gz securewhisper-4a3ae9929f4657a0f2e9ccf393205655895bb501.tar.xz securewhisper-4a3ae9929f4657a0f2e9ccf393205655895bb501.zip | |
Add files via upload
Diffstat (limited to 'security/crypto.py')
| -rw-r--r-- | security/crypto.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/security/crypto.py b/security/crypto.py new file mode 100644 index 0000000..f961a21 --- /dev/null +++ b/security/crypto.py @@ -0,0 +1,37 @@ +from pyspx.shake_256f import generate_keypair, sign, verify +import hashlib +from typing import Tuple, Optional +import os + +class CryptoManager: + def __init__(self): + self.signing_key: Optional[bytes] = None + self.verify_key: Optional[bytes] = None + + def generate_keys(self) -> Tuple[bytes, bytes]: + """Generate new signing keypair""" + self.signing_key, self.verify_key = generate_keypair() + return self.signing_key, self.verify_key + + def sign_message(self, message: bytes) -> bytes: + """Sign a message using the signing key""" + if not self.signing_key: + raise ValueError("No signing key available") + return sign(message, self.signing_key) + + def verify_signature(self, message: bytes, signature: bytes, + public_key: bytes) -> bool: + """Verify a message signature""" + try: + verify(message, signature, public_key) + return True + except: + return False + + def hash_data(self, data: bytes) -> str: + """Create SHA-256 hash of data""" + return hashlib.sha256(data).hexdigest() + + def generate_nonce(self) -> bytes: + """Generate a random nonce""" + return os.urandom(32) |
