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);
上面的代码使用从xml加载的PrivateKey对字符串进行签名。
你能帮我在python中重写它吗?
我自己编写了这段代码,但它产生了不同的签名!
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)))