2019年12月3日 星期二

How to View the RSA Verification Data

"""
To view the RSA verification data:
    s = m^d mod n,   and     v = s^e mod n
  =>
    signature = ( message ^ key.D ) mod key.N
    verify (or message) = ( signature ^ key.E ) mod key.N
"""
from Crypto.PublicKey import RSA
from Crypto.Util import number

kf = open('Key.pem', 'r')
myPrivKey = RSA.importKey(kf.read())
kf.close()

fin = open('Signature.bin', 'rb')
signature = bytearray(fin.read())
fin.close()

msg_long = number.bytes_to_long(signature)
veridata = pow(msg_long, myPrivKey.e, myPrivKey.n)
print("%x" %veridata)

沒有留言:

張貼留言

Binary Data, String, and Integer Conversions in Python

In Python 3, struct  will interpret bytes as packed binary data: This module performs conversions between Python values and C structs rep...