During development we were using the Self Signed Certificate from IIS 8 for developing/testing Provider Hosted App we are working on.
Now we need to make changes to the app for Packaging and Publishing. I am following the MSDN documentation Package and publish high-trust apps for SharePoint 2013
I have made the changes in the project, as explained in the MSDN documentation but having issue in the TokenHelper.cs code
private static X509SigningCredentials GetSigningCredentials(X509Certificate2 cert)
{
return (cert == null) ? null
: new X509SigningCredentials(cert,
SecurityAlgorithms.RsaSha256Signature,
SecurityAlgorithms.Sha256Digest);
}
private static X509Certificate2 GetCertificateFromStore()
{
if (string.IsNullOrEmpty(ClientSigningCertificateSerialNumber))
{
return null;
}
// Get the machine's personal store
X509Certificate2 storedCert;
X509Store store = new X509Store(StoreName.My, StoreLocation.LocalMachine);
try
{
// Open for read-only access
store.Open(OpenFlags.ReadOnly);
// Find the cert
storedCert = store.Certificates.Find(X509FindType.FindBySerialNumber,
ClientSigningCertificateSerialNumber,
true)
.OfType<X509Certificate2>().SingleOrDefault();
}
finally
{
store.Close();
}
return storedCert;
}
I have the certificate show up in
store.Certificates
but the Find method returns an empty collection. Because of which I am getting SigningCredentials was not initialized exception.
Things I verfied -
- Went through the steps twice, as mentioned in the MSDN documentation
- Checked the serial number in the web config is correct and all CAPs.
- Self Signed Certificate (.pfx) installed under Personal -> Certificates in Microsoft Certificate Store.
Note - I am doing these steps with Self Signed Certificate and once these steps are successful will be getting the commercial certificate from a CA and proceed to package the app.