在将数据发送到服务之前,我需要对其进行签名。我是通过以下方法在Windows应用程序中完成的:
private string SignWithPfx(string data)
{
var path = AppDomain.CurrentDomain.BaseDirectory + "certificate.pfx";
var password = "1234";
var collection = new X509Certificate2Collection();
collection.Import(path, password, X509KeyStorageFlags.Exportable);
var certificate = collection[0];
var publicKey = certificate.PublicKey.Key as RSACryptoServiceProvider;
var privateKey = certificate.PrivateKey as RSACryptoServiceProvider;
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
rsa.FromXmlString(certificate.PrivateKey.ToXmlString(true));
var signature = rsa.SignData(Encoding.ASCII.GetBytes(data), CryptoConfig.MapNameToOID("SHA256"));
return Convert.ToBase64String(signature);
}
但是当我将其传输到Silverlight项目时,我注意到这里没有“ X509Certificate2Collection”甚至“ RSACryptoServiceProvider”! 我该怎么办?