Klucz nie dziala na serwerze

0

Wiec mam kod ktory za pomoca public key i private key sprawdza sygnature i odkodowywuje tekst.

Super wszystko dziala lokalnie

Robie Deploy aplikacji. Jest ona hostowana w Azure.

dostaje Exception

Invalid provider type specified.


{
  "Message": "Invalid provider type specified.\r\n",
  "Data": {},
  "InnerException": null,
  "StackTrace": "   at System.Security.Cryptography.Utils.CreateProvHandle(CspParameters parameters, Boolean randomKeyContainer)\r\n   at System.Security.Cryptography.Utils.GetKeyPairHelper(CspAlgorithmType keyType, CspParameters parameters, Boolean randomKeyContainer, Int32 dwKeySize, SafeProvHandle& safeProvHandle, SafeKeyHandle& safeKeyHandle)\r\n   at System.Security.Cryptography.RSACryptoServiceProvider.GetKeyPair()\r\n   at System.Security.Cryptography.RSACryptoServiceProvider..ctor(Int32 dwKeySize, CspParameters parameters, Boolean useDefaultKeySize)\r\n   at System.Security.Cryptography.X509Certificates.X509Certificate2.get_PrivateKey()\r\n   at System.Security.Cryptography.X509Certificates.RSACertificateExtensions.GetRSAPrivateKey(X509Certificate2 certificate)\r\n   
at CertificateManager.cs:line 100",
  "HelpLink": null,
  "Source": "mscorlib"
}

linijka kodu to

privateKey = certificate.GetRSAPrivateKey();

GetRSAPrivateKey od razu wyrzuca wyjatek. Nawet nie mozna sprawdzic typu jaki jest zwracany PrivateKey. Odwolanie sie do PrivateKey sprawia natychmiastowy exception (ten ktory jest na gorze)

  1. postawilem VM z taka sama wersja OS ktora jest na Azure => Dziala lokalnie
  2. zmienilem certyfikat na csp zgodznie z https://remyblok.tweakblogs.net/blog/11803/converting-certificate-to-use-csp-storage-provider-in-stead-of-cng-storage-provider. Lokalnie dziala. Deploy nie dziala

Co mozna zrobic wiecej by jakos ruszyc?

0

po dodaniu

var flags = X509KeyStorageFlags.MachineKeySet
                    | X509KeyStorageFlags.PersistKeySet
                    | X509KeyStorageFlags.Exportable;

dziala jak trzeba, Posiadanie samego exportable powodowalo ze na serwerze nie dziala :D

1 użytkowników online, w tym zalogowanych: 0, gości: 1