Skip to content
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
48 lines (39 sloc) 1.31 KB
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# Author: wxnacy(
# Description:
from Crypto import Random
from Crypto.Hash import SHA
from Crypto.Signature import PKCS1_v1_5
from Crypto.PublicKey import RSA
import base64
def signature(message, rsa_path):
with open(rsa_path) as f:
key =
rsakey = RSA.importKey(key)
signer =
digest =
sign = signer.sign(digest)
signature = base64.b64encode(sign)
return signature
def verify_signature(message, signature, pub_rsa_path):
with open(pub_rsa_path) as f:
key =
rsakey = RSA.importKey(key)
verifier =
digest =
# Assumes the data is base64 encoded to begin with
is_verify = verifier.verify(digest, base64.b64decode(signature))
return is_verify
if __name__ == "__main__":
plain = 'message'
pub_rsa_path = '/Users/wxnacy/.ssh/'
rsa_path = '/Users/wxnacy/.ssh/id_rsa'
sign = signature(plain, rsa_path)
print('签名:', sign)
flag = verify_signature(plain, sign, pub_rsa_path)
print('验证结果:', flag)
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.