Spaces:
Runtime error
Runtime error
| import streamlit as st | |
| import hashlib | |
| import cryptography | |
| from cryptography.hazmat.primitives import hashes | |
| from cryptography.hazmat.primitives.asymmetric import ( | |
| padding, rsa, utils | |
| ) | |
| private_key = rsa.generate_private_key( | |
| public_exponent=65537, | |
| key_size=512, | |
| ) | |
| st.write(""" | |
| ## Tanda Tangan Digital RSA🔐 | |
| """) | |
| input = st.text_input('Masukkan Teks', 'Informatika 2022') | |
| prehashed_msg = hashlib.sha256(input.encode()).digest() | |
| signature = private_key.sign( | |
| prehashed_msg, | |
| padding.PSS( | |
| mgf=padding.MGF1(hashes.SHA256()), | |
| salt_length=padding.PSS.MAX_LENGTH | |
| ), | |
| utils.Prehashed(hashes.SHA256()) | |
| ) | |
| if st.button('Klik untuk generate'): | |
| st.write("Tanda tangan digital :\n", signature) | |
| public_key = private_key.public_key() | |
| try : | |
| public_key.verify( | |
| signature, | |
| prehashed_msg, | |
| padding.PSS( | |
| mgf=padding.MGF1(hashes.SHA256()), | |
| salt_length=padding.PSS.MAX_LENGTH | |
| ), | |
| utils.Prehashed(hashes.SHA256()) | |
| ) | |
| #st.write("publik key:", public_key) | |
| st.write('Tanda tangan VALID') | |
| except InvalidSignature: | |
| st.write('Tanda tangan INVALID') |