There is my context: We have Xamarin.Forms App that receive a certificate from the server in Base64 String with \n\r. I want to put this certificate in KeyStore so I'm doing this code :
var ks = KeyStore.GetInstance("AndroidKeyStore");
ks.Load(null);
if (ks.ContainsAlias(RSAStrings.ServerCertificateName))
{
ks.DeleteEntry(RSAStrings.ServerCertificateName);
}
var cerBase64 = "-----BEGIN CERTIFICATE-----" + Environment.NewLine + cer + "-----END CERTIFICATE-----" + Environment.NewLine;
var cerBytes = System.Text.UTF8Encoding.UTF8.GetBytes(cerBase64);
var memStream = new MemoryStream(cerBytes);
this.serverCertificate = CertificateFactory.GetInstance("X.509").GenerateCertificate(memStream);
ks.SetCertificateEntry(RSAStrings.ServerCertificateName, this.serverCertificate);
When GenerateCertificate, I got error "inStream is empty", but my MemoryStream contains all bytes, I can see it.
Any help will be appreciated.
Thank you !