Answer the question
In order to leave comments, you need to log in
Why are RSA signatures different in php and python?
I'm not strong in php, there is such a code that gives a signature
$json_data=json_encode($data);
$sha1_json_data=sha1($json_data);
$priv_key = openssl_pkey_get_private($key);
$encrypted = '';
openssl_private_encrypt($sha1_json_data, $encrypted, $priv_key);
$b64_encrypted=base64_encode($encrypted);
jd = json.dumps(data).replace(' ', '').encode('utf8')
# тут данные получаются один в один как в php
with open(BASE_DIR / "local_files/contract.key", "rb") as key_file:
import rsa
key = key_file.read()
contract_key = rsa.PrivateKey.load_pkcs1(key)
signature = rsa.sign(jd, contract_key, 'SHA-1')
print(str(b64encode(signature), encoding="utf-8"))
from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.asymmetric import padding
private_key = serialization.load_pem_private_key(key, password=None)
signature = private_key.sign(
jd,
padding.PKCS1v15(),
hashes.SHA1()
)
print(str(b64encode(signature), encoding="utf-8"))
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question