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下获取。
1 string keyID = cert.SerialNumber.ToString(); 2 System.Security.Cryptography.X509Certificates.X509Store store = new System.Security.Cryptography.X509Certificates.X509Store(System.Security.Cryptography.X509Certificates.StoreName.Root); 3 4 store.Open(System.Security.Cryptography.X509Certificates.OpenFlags.ReadOnly); 5 6 System.Security.Cryptography.X509Certificates.X509Certificate2Collection x509CertCollections = store.Certificates; 7 8 var certs = store.Certificates.Find(System.Security.Cryptography.X509Certificates.X509FindType.FindBySerialNumber, keyID, true); 9 if (certs.Count == 0) 10 { 11 return false; 12 }
2、在windows平台获取根证书方法。
3、IOS待补充。。。