I am beginner to read the google spread using service account in my project .For few days it work fine but now i got an exception as
System.Security.Cryptography.CryptographicException: Invalid provider type specified.
Here is the stack trace
at System.Security.Cryptography.Utils.CreateProvHandle(CspParameters parameters, Boolean randomKeyContainer)
at System.Security.Cryptography.Utils.GetKeyPairHelper(CspAlgorithmType keyType, CspParameters parameters, Boolean randomKeyContainer, Int32 dwKeySize, SafeProvHandle& safeProvHandle, SafeKeyHandle& safeKeyHandle)
at System.Security.Cryptography.RSACryptoServiceProvider.GetKeyPair() at System.Security.Cryptography.RSACryptoServiceProvider..ctor(Int32 dwKeySize, CspParameters parameters, Boolean useDefaultKeySize)
at System.Security.Cryptography.X509Certificates.X509Certificate2.get_PrivateKey()
at Google.Apis.Auth.OAuth2.ServiceAccountCredential.Initializer.FromCertificate(X509Certificate2 certificate)
By seeing this stack trace I came to know that it can't read the certificate.
here is my code:
string applicationName = "QA Automation";
var serviceaccountemail = "Myaccount.gserviceaccount.com";
var certificate = new X509Certificate2(GetCertificateBytes(), "*****", X509KeyStorageFlags.Exportable);
ServiceAccountCredential credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer(serviceaccountemail)
{
Scopes = new[] { "https://spreadsheets.google.com/feeds" }
}.FromCertificate(certificate));
var service = new SheetsService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = applicationName,
});
String spreadsheetId = "**************************************";//spreadId
String range = "Sheet1!A1:C";
SpreadsheetsResource.ValuesResource.GetRequest request =
service.Spreadsheets.Values.Get(spreadsheetId, range);
ValueRange response = request.Execute();
at .FromCeritificate(Certificate) got the exception. I have researched on this exception "Invalid provider type" .I got the results as it is permission of IIS . Is there any other solution to do this ?
Thanks in advance.