I'm using a self-signed certificate for connection to SharePoint using Application Permissions.
The reference to the Key Vault value in the configuration is set as this:
@Microsoft.KeyVault(SecretUri=https://keyvaultname.vault.azure.net/certificates/NameOfMyCertificate/id)
The secret Uri is easily obtained from the Key Vault. It is called Certificate Identifier, and is located in the properties of the certificate in Azure Key Vault.
For the Azure Function to be able to access the certificate in Key Vault, it should have a managed identity activated and a proper access policy to Get Certificates.
The value that is loaded in the configuration variable is indeed a base64 string. The code I used to load the certificate is as follows:
public static X509Certificate2 ReadCertificateFromBase64StringPfx(string base64Pfx)
{
byte[] certBytes = Convert.FromBase64String(base64Pfx);
X509Certificate2Collection collection = new X509Certificate2Collection();
collection.Import(certBytes, string.Empty, X509KeyStorageFlags.PersistKeySet);
return collection[0];
}
If you have more than one certificate in the PFX, you will need to change the return value and select the proper certificate from the collection.
NOTE: You must also add WEBSITE_LOAD_USER_PROFILE=1 in the configuration of your Azure Function, otherwise you will get an error stating that Import function was unable to find the file. Check this source.