0

Have implemented some https support infrastructure. In one place need to Convert RSA to pem format. Here found the solution, that works fine on Windows, but as soon as run it in docker with linux, after the construction

var parameters = rsa.ExportParameters(true); have got next error

System.Security.Cryptography.CryptographicException Cannot open an invalid handle. Void CheckInvalidKey(Microsoft.Win32.SafeHandles.SafeRsaHandle)   

Is there any alternative to export RSA in pem format ? If not is there any alternative way to get parameters from RSA ?

President James K. Polk
  • 40,516
  • 21
  • 95
  • 125
Vitalii
  • 127
  • 1
  • 12
  • There are always alternatives, but we'd need to know why you are trying to export it in "PEM" format (which is not really a format after all). Knowing more about the requirements of the software that will be consuming this "PEM" private key would be a good start. – President James K. Polk Nov 08 '18 at 18:11
  • Where did you get the RSA object, did you perhaps already dispose it? – bartonjs Nov 09 '18 at 02:21
  • Thanks for your comment, I've tested it's not disposed and It works on Windows OS. @JamesKPolk thanks for your question. Other components that consume the result of the method I've written expect to see "PEM" format. It's clear that it's not a format like X509 it's just a plain text with Header Base64 and footer, and the algorithm I've found to Convert pvk by the link above looks very complicated and by some steps ( some deltas seems to supports some legacy requirements. Will be appreciated if you can suggest some better to support format to export private RSA key workable in .Net Standard! – Vitalii Nov 09 '18 at 11:37
  • More strange thing I've found that the same code instruction var parameters = rsa.ExportParameters(true); works fine even on Linux if it's inside .Net Core. Seems it's issue more related to understanding the difference of compilation .Net Core and .Net Standard project. – Vitalii Nov 09 '18 at 11:45
  • @ВиталийАйрапетян There shouldn't be any difference, but if you can come up with a sharable repro, please open an issue at https://github.com/dotnet/corefx/. – bartonjs Nov 09 '18 at 15:51

0 Answers0