Spaces:
Runtime error
Runtime error
Upload 2 files
Browse files- app.py +46 -0
- requirements1.txt +2 -0
app.py
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import hashlib
|
3 |
+
import cryptography
|
4 |
+
from cryptography.hazmat.primitives import hashes
|
5 |
+
from cryptography.hazmat.primitives.asymmetric import (
|
6 |
+
padding, rsa, utils
|
7 |
+
)
|
8 |
+
private_key = rsa.generate_private_key(
|
9 |
+
public_exponent=65537,
|
10 |
+
key_size=512,
|
11 |
+
)
|
12 |
+
|
13 |
+
st.write("""
|
14 |
+
## Tanda Tangan Digital RSA🔐
|
15 |
+
""")
|
16 |
+
input = st.text_input('Masukkan Teks', 'Informatika 2022')
|
17 |
+
|
18 |
+
prehashed_msg = hashlib.sha256(input.encode()).digest()
|
19 |
+
signature = private_key.sign(
|
20 |
+
prehashed_msg,
|
21 |
+
padding.PSS(
|
22 |
+
mgf=padding.MGF1(hashes.SHA256()),
|
23 |
+
salt_length=padding.PSS.MAX_LENGTH
|
24 |
+
),
|
25 |
+
utils.Prehashed(hashes.SHA256())
|
26 |
+
)
|
27 |
+
if st.button('Klik untuk generate'):
|
28 |
+
st.write("Tanda tangan digital :\n", signature)
|
29 |
+
|
30 |
+
public_key = private_key.public_key()
|
31 |
+
|
32 |
+
try :
|
33 |
+
public_key.verify(
|
34 |
+
signature,
|
35 |
+
prehashed_msg,
|
36 |
+
padding.PSS(
|
37 |
+
mgf=padding.MGF1(hashes.SHA256()),
|
38 |
+
salt_length=padding.PSS.MAX_LENGTH
|
39 |
+
),
|
40 |
+
utils.Prehashed(hashes.SHA256())
|
41 |
+
)
|
42 |
+
|
43 |
+
#st.write("publik key:", public_key)
|
44 |
+
st.write('Tanda tangan VALID')
|
45 |
+
except InvalidSignature:
|
46 |
+
st.write('Tanda tangan INVALID')
|
requirements1.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
cryptography==3.4.8
|
2 |
+
streamlit==1.12.2
|