private static string findThePublicKey(Pkcs12Store pkcs12Store)
{
var alias = string.Empty;
foreach (var entry in pkcs12Store.Aliases.Cast<string>().Where(entry => pkcs12Store.IsKeyEntry(entry) && pkcs12Store.GetKey(entry).Key.IsPrivate))
{
alias = entry;
break;
}
if (string.IsNullOrEmpty(alias))
throw new InvalidOperationException("Provided certificate is invalid.");
return alias;
}