I'm using someone else's code to generate an RSA signature used for verification in xbox 360 save files. The code reads the needed values from a files and correctly generates the signature.
The code is:
byte[] xHash=null;
RSAParameters xParams = new RSAParameters();
br.BaseStream.Position = 0x1A8;
xParams.D = br.ReadBytes(0x80);
xParams.Exponent = br.ReadBytes(0x4);
xParams.Modulus = br.ReadBytes(0x80);
xParams.P = br.ReadBytes(0x40);
xParams.Q = br.ReadBytes(0x40);
xParams.DP = br.ReadBytes(0x40);
xParams.DQ = br.ReadBytes(0x40);
xParams.InverseQ = br.ReadBytes(0x40);
br.close();
br=new BinaryReader(File.OpenRead(f));
br.BaseStream.Position=0x22c;
xHash = new SHA1CryptoServiceProvider().ComputeHash(br.ReadBytes(0x118));
byte[] xrsa=SignatureGenerate(xParams, xHash);
public static byte[] SignatureGenerate(RSAParameters xParam, byte[] xHash)
{
RSACryptoServiceProvider xRSACrypto = new RSACryptoServiceProvider();
RSAPKCS1SignatureFormatter xRSASigFormat = new RSAPKCS1SignatureFormatter();
xRSACrypto.ImportParameters(xParam);
xRSASigFormat.SetHashAlgorithm("SHA1");
xRSASigFormat.SetKey(xRSACrypto);
return xRSASigFormat.CreateSignature(xHash);
}
I'm trying to end up with what's in xrsa, but using Python. I installed pycrypto, and I'm looking at the documentation, but I'm still missing something obvious. First, the RSA.construct from Crypto.PublicKey only takes six parameters, but not the exponents one and two (DP and DQ). Also, the inputs need to be longs. In the C# code, the values were 128 and 64 bytes long, as opposed to a 4 byte long.
I know this may seem painfully obvious, but I have no idea what I need to do.
I'm working with Python 2.7.3
edit: also, the "message" to be encrypted is a sha1 hash of 0x118 bytes of the file, which contains meta data and a hash of other parts of the file.
edit: Thank you so much mata, I feel I'm closer to getting it working. It still doesn't match the C# signature. In C#, the signature format is being set as SHA1. What is this doing, and can it be done in Python?