Home > other >  Using the python implementation rsautl - sign the order
Using the python implementation rsautl - sign the order

Time:11-09

Background: the original implementation is through the OpenSSL command, now will end with a python implementation,
The original command is as follows:
# on file with the sha256 get hash
Openssl DGST - sha256 - binary - out $DEC_FILE $IN_FILE
# to get the hash sign
Openssl rsautl - sign - inkey $RSA_KEY - in $DEC_FILE - out $ENC_FILE - PKCS

I use the following method to realize at present:
 
The from cryptography. Hazmat. Backends import default_backend
The from cryptography. Hazmat. Primitives import serialization

The from cryptography. Hazmat. Primitives import hashes
The from cryptography. Hazmat. Primitives. The asymmetric import padding

.
TXT=text + "\ n"
Sha=SHA256. New ()
Sha. Update (. TXT encode (' utf8))

Print (" the message: ")
Print (TXT)
Print (" hexdigest: ")
Print (sha) hexdigest ())

# read private key data from PEM file
Key_file=open (prikey, 'rb')
Key_data=(https://bbs.csdn.net/topics/key_file.read)
Key_file. Close ()

# from PEM file data loading private key
Private_key=serialization. Load_pem_private_key (
Key_data,
Password=None,
Backend=default_backend ()
)

# using the private key signature data
# designated filling way for PKCS1v15
# assigned to sha256 hash
Sha_sig=private_key. Sign (
Sha. Digest (),
Padding. PKCS1v15 (),
Hashes. SHA256 ()
)
.


Results:
Found my signature after implementation solve would bring format, as follows:
3031300 d0609608648016503040201050004201525c08fdeec19e24ddd558373408358b59e18455a3cdd80208f255ad0a9a319
Is at the back of the original with the OpenSSL command came to 64 bytes, as follows:
1525 c08fdeec19e24ddd558373408358b59e18455a3cdd80208f255ad0a9a319

Note: using the openssl rsautl - sign, rather than the openssl DGST - sha1 - sign,

Problem: in view of this situation, I on the premise of not let the other side to modify, if there is a class can implement the original in python with OpenSSL encrypted result, which is the result of the signature contains hash content, only those without signature format
  • Related