M
M
MalikDeveloper20772020-12-01 18:37:09
Python
MalikDeveloper2077, 2020-12-01 18:37:09

RSA Verify signature (Or compare HEX hashes) SHA512. pycryptodom?

The service has a private key, I have a public key.
The service wrote: “Encrypt the data using RSA SHA512, compare it with the given HEX hash. If the encrypted data matches the specified data, the operation will complete successfully."

I think it's signature verification but I'm not sure, please explain to me.
My public key:

-----BEGIN RSA PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzsyBqCUMdYwNdRTMPYxV
4/DbvtUVv8U7BC3PdvXbZFLwC9CMCEfwzMisDppRJVUhoPs+o4rO1SIOTGKbYZl0
CDvz6sxjO40NcoX57qA4WdPVYp6gxrLwRgs7Od2nzTtwq6gjagYhysZZJdybShzz
am3K2KEjedi4YrJDCVJlSJB5yAKM242jK8sCPboNy3EASVUavLBQE9pnisZPYyuf
ThiAZY9mXKmK60FthFg9R8vVb2Ug/iKKHdbp/cNiFnIm5PMDUMV0XF2YHtr9Ft8t
D8Ub0c5oZbKmKsXvE/zjb06K153utY4KOE+BIJx0xc8qxhudYdcQhEusxaKu9+Zn
FwIDAQAB
-----END RSA PUBLIC KEY-----


I wrote this code
from Crypto.Signature import PKCS1_v1_5
from Crypto.PublicKey import RSA
from Crypto.Hash import SHA512


data = b'mdOrder;2930808c-6fa8-71f5-b6ff-54085e4149db;operation;deposited;orderNumber;#19, , kalik;sign_alias;stoloto;status;1;'  # Data to encrypt
given_hash = "94463EB342F8DEE6F70497383DE9F0802A4FF6450D6B4B97FD5E5A72E4AB7EDA708DCE525DF9E30296FBF22C19CE509FD2A4AA76D7C0A48187307903328B2FEFDB707A71A8A407B4A4C41399D8302C0D01F5E0EA89BDEBD7E22D8763CCFB83254C4D82F9FD4D6D8146B5538AB552016C89BA7E509CF26296ABEACD79CE74B30AF01902670A434B44F0F8AB94B0BCEEE1DFE6DC052AB76B7D6BE9B8507296E66FBA3C7E024B6CB828061D54F92D66D8FE8955F2F6C10FC8FF7A281BD399B0FD5F40C46440A6B8FDEA4E5718C12ECF11C4952089FA26A7A3D6AB8BAE8D02C598133A2FB8DD85109EDAC2301C492DCB55FFA54C508349A51AD735573B8CC8D71518"  # The service hash (given in uppercase)

pubkey = RSA.import_key(PUBLIC_KEY)
signer = PKCS1_v1_5.new(pubkey)
hash_ctx = SHA512.new()
hash_ctx.update(data)
signature = signer.sign(hash_ctx)

signer.verify(hash_ctx, signature)


But this code does not use given_hash, and hash_ctxis not even a Hash object, signatureis wrong.
So I just don't understand how to solve this...
Since this is a specific case, I think I need to encrypt the given in SHA512, format it in uppercase, and then compare.

Should I just encrypt my message ( data) with the public key and compare it to the given hash just with ==?
If this is correct, please help me write the code

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question