Exp 3 Csy
Exp 3 Csy
Theory:
Message Digest
SHA-256 (Secure Hash Algorithm - 256 bit) is a cryptographic hash function that produces a
unique 256-bit (32-byte) hash value for an input message. It is widely used in security
protocols like SSL/TLS, blockchain technology, and digital signatures.
Properties of SHA-256:
• Preimage Resistance: It is infeasible to determine the original message from the hash.
• Small Change, Big Impact: Even a minor change in input causes a drastic change in the
hash.
Asymmetric Encryption
This method provides higher security compared to symmetric encryption, where a single key
is used for both encryption and decryption.
Public & Private Key in Digital Signatures
• The public key is used by the recipient to verify that the message was signed by the
corresponding private key holder.
This ensures authenticity, as only the private key owner can generate a valid signature.
1. Message Hashing: The sender generates a hash (message digest) using SHA-256.
2. Signature Generation: The hash is encrypted using the sender’s private key to create a
digital signature.
3. Transmission: The original message and the digital signature are sent to the recipient.
4. Verification: The recipient decrypts the signature using the sender’s public key and
compares the extracted hash with the hash of the received message. If they match, the
signature is valid.
1) cryptography.hazmat.primitives
2) rsa
A Python library that allows RSA-based encryption, decryption, key pair generation, and
digital signatures. It is widely used for implementing public-key cryptography.
3) padding
Padding is used to ensure that the input message conforms to a required block size for
encryption. Without padding, RSA encryption may fail for short messages.
Methods Used:
1) rsa.generate_private_key()
2) padding.PKCS1v15()
• A widely used padding scheme for RSA encryption and digital signatures.
Code :
signature = private_key.sign(
message,
padding.PKCS1v15(),
hashes.SHA256()
try:
public_key.verify(
signature,
message,
padding.PKCS1v15(),
hashes.SHA256()
except Exception:
Conclusion:
This digital signature using rsa implementation demonstrates securely signing a message with
a private key and verifying its authenticity using the corresponding public key.