I have .pfx file using which I want to Sign the data in android in the same way in which my team has done in C#.
I am not finding a way for extracting Private key from .pfx file and sign using RSA with SHA256 in Android (Java).
Code for C#
private static byte[] EncryptUsingDigitalSignature(byte[] hashBytes)
{
try
{
X509Certificate2 cert = new X509Certificate2(AppDomain.CurrentDomain.BaseDirectory + "\\Certificate\\abc.pfx", "1234", X509KeyStorageFlags.Exportable);
var cspParams = new CspParameters(24) { KeyContainerName = "XML_DSIG_RSA_KEY" };
var key = new RSACryptoServiceProvider(cspParams);
key.FromXmlString(cert.PrivateKey.ToXmlString(true));
return key.SignHash(hashBytes, CryptoConfig.MapNameToOID("SHA256"));
}
catch(Exception ex)
{
Write_Log("GetDigitalSignature: " + ex.Message + " Path :" + AppDomain.CurrentDomain.BaseDirectory + @"\Certificate\abc.pfx");
throw ex;
}
}
Thank you in advance.