xamarin android 获取根证书代码

时间:2022-03-19 03:19:01
Java.Security.KeyStore keyStore = Java.Security.KeyStore.GetInstance("AndroidCAStore");
keyStore.Load(null, null);
Java.Util.IEnumeration keyAliases = keyStore.Aliases();
while (keyAliases.HasMoreElements)
{
string alias = (string)keyAliases.NextElement();
//系统默认CA开头为system 用户的为user
if (alias.StartsWith("system"))
{
Java.Security.Cert.X509Certificate cert2 = (Java.Security.Cert.X509Certificate)keyStore.GetCertificate(alias);
if (keyID == cert2.SerialNumber.ToString())
{
isTrustRoot = true;
}
}
}

  1、获取android根证书方法C#、xamarin.droid下获取。

 string keyID = cert.SerialNumber.ToString();
System.Security.Cryptography.X509Certificates.X509Store store = new System.Security.Cryptography.X509Certificates.X509Store(System.Security.Cryptography.X509Certificates.StoreName.Root); store.Open(System.Security.Cryptography.X509Certificates.OpenFlags.ReadOnly); System.Security.Cryptography.X509Certificates.X509Certificate2Collection x509CertCollections = store.Certificates; var certs = store.Certificates.Find(System.Security.Cryptography.X509Certificates.X509FindType.FindBySerialNumber, keyID, true);
if (certs.Count == )
{
return false;
}

2、在windows平台获取根证书方法。

3、IOS待补充。。。