1 var filePath=""; 2 var message=""; 3 var mchid=""; 4 using (var cert = new X509Certificate2(filePath, mchid)) 5 { 6 byte[] data = Encoding.UTF8.GetBytes(message); 7 using (RSA rsa = cert.GetRSAPrivateKey()) 8 { 9 var signData = rsa.SignData(data, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1); 10 return Convert.ToBase64String(signData); 11 } 12 }