RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
rsa.FromXmlString(PrivateKey);
string data = "SAMPLE TEXT.";
byte[] signedData = rsa.SignData(Encoding.UTF8.GetBytes(data), new
SHA1CryptoServiceProvider());
string signedString = Convert.ToBase64String(signedData);
The code above signs a string with a PrivateKey loaded from an xml.
Would you help me rewrite it in python?
I wrote this code myself but it produce a different signature!
from Crypto.PublicKey import RSA
from Crypto.Util.number import bytes_to_long, long_to_bytes
from hashlib import sha1
import base64
msg = "SAMPLE TEXT."
hashed = sha1(msg.encode('utf-8')).digest()
pubkey = RSA.construct((m,e))
encrypted = pubkey.encrypt(hashed, b'X')[0]
print("Signature: {0}".format(base64.b64encode(encrypted)))