strangerRidingCaml
5. Hash Functions and Digital Signatures 본문
728x90
Hash Functions and Digital Signatures
Cryptographic Hash Functions
SHA-2 : A family of cryptographic hash functions including SHA-256, SHA-384, and SHA-512.SHA-3 : The latest member of the Secure Hash Algorithm family, designed to provide better security and performance than SHA-2.
Digital Signatures
RSA : A widely-used public-key cryptosystem for secure communication and digital signatures.DSA (Digital Signature Algorithm) : A Federal Information Processing Standard for digital signatures, designed for faster signing and verification compared to RSA.ECDSA (Elliptic Curve Digital Signature Algorithm) : A variant of DSA using elliptic curve cryptography, offering shorter key lengths and faster performance.
Applications of Digital Signatures
Authentication : Verifying the identity of the sender in electronic transactions.Integrity : Ensuring the integrity of transmitted data by detecting any unauthorized modifications.Non-repudiation : Preventing the sender from denying the authenticity or integrity of the message.
Laboratory Activities
Lab 1: Digital Signature Generation and Verification using RSA in Python
from Crypto.PublicKey import RSA
from Crypto.Signature import pkcs1_15
from Crypto.Hash import SHA256
def generate_rsa_signature(message, private_key):
hash_obj = SHA256.new(message)
signature = pkcs1_15.new(private_key).sign(hash_obj)
return signature
def verify_rsa_signature(message, signature, public_key):
hash_obj = SHA256.new(message)
try:
pkcs1_15.new(public_key).verify(hash_obj, signature)
return True
except (ValueError, TypeError):
return False
key = RSA.generate(2048)
public_key = key.publickey()
private_key = key
message = b"Hello World"
signature = generate_rsa_signature(message, private_key)
verification_result = verify_rsa_signature(message, signature, public_key)
print("Message: ", message)
print("Signature: ", signature)
print("Verification Result: ", verification_result)
This lab demonstrates the generation and verification of digital signatures using RSA in Python.
Lab 2: Digital Signature Generation and Verification using ECDSA in Python
from Crypto.PublicKey import ECC
from Crypto.Signature import DSS
from Crypto.Hash import SHA256
def generate_ecdsa_signature(message, private_key):
hash_obj = SHA256.new(message)
signer = DSS.new(private_key, 'fips-186-3')
signature = signer.sign(hash_obj)
return signature
def verify_ecdsa_signature(message, signature, public_key):
hash_obj = SHA256.new(message)
verifier = DSS.new(public_key, 'fips-186-3')
try:
verifier.verify(hash_obj, signature)
return True
except (ValueError, TypeError):
return False
key = ECC.generate(curve='P-256')
public_key = key.public_key()
private_key = key
message = b"Hello World"
signature = generate_ecdsa_signature(message, private_key)
verification_result = verify_ecdsa_signature(message, signature, public_key)
print("Message: ", message)
print("Signature: ", signature)
print("Verification Result: ", verification_result)
This lab demonstrates the generation and verification of digital signatures using ECDSA in Python.
'Modern cryptography' 카테고리의 다른 글
7. Advanced Topics (0) | 2024.05.06 |
---|---|
6. Cryptographic Protocols (0) | 2024.05.06 |
4. Public-Key Cryptography (0) | 2024.05.06 |
3. Symmetric Cryptography (0) | 2024.05.06 |
2. Classical Cryptography (0) | 2024.05.06 |