mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-27 03:24:24 +00:00
35 lines
760 B
Python
Executable File
35 lines
760 B
Python
Executable File
#!/usr/bin/env python3
|
|
# -*- coding:utf-8 -*
|
|
#
|
|
# Skia < skia AT libskia DOT so >
|
|
#
|
|
# Beerware licensed software - 2017
|
|
#
|
|
|
|
import base64
|
|
from OpenSSL import crypto
|
|
|
|
with open("./private_key.pem") as f:
|
|
PRVKEY = f.read()
|
|
with open("./public_key.pem") as f:
|
|
PUBKEY = f.read()
|
|
|
|
data = "Amount=400&BasketID=4000&Auto=42&Error=00000\n".encode("utf-8")
|
|
|
|
# Sign
|
|
prvkey = crypto.load_privatekey(crypto.FILETYPE_PEM, PRVKEY)
|
|
sig = crypto.sign(prvkey, data, "sha1")
|
|
b64sig = base64.b64encode(sig)
|
|
print(b64sig)
|
|
|
|
# Verify
|
|
pubkey = crypto.load_publickey(crypto.FILETYPE_PEM, PUBKEY)
|
|
cert = crypto.X509()
|
|
cert.set_pubkey(pubkey)
|
|
sig = base64.b64decode(b64sig)
|
|
try:
|
|
crypto.verify(cert, sig, data, "sha1")
|
|
print("Verify OK")
|
|
except:
|
|
print("Verify failed")
|