示例#1
0
文件: vfs.cs 项目: tianlian0/ikvm
            private void Populate()
            {
                if (buf == null)
                {
                    global::java.security.KeyStore jstore = global::java.security.KeyStore.getInstance("jks");
                    jstore.load(null);
                    global::java.security.cert.CertificateFactory cf = global::java.security.cert.CertificateFactory.getInstance("X509");

                    X509Store store = new X509Store(StoreName.Root, StoreLocation.LocalMachine);
                    store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
                    Dictionary <string, string> aliases = new Dictionary <string, string>();
                    foreach (X509Certificate2 cert in store.Certificates)
                    {
                        if (!cert.HasPrivateKey)
                        {
                            // the alias must be unique, otherwise we overwrite the previous certificate with that alias
                            string alias  = cert.Subject;
                            int    unique = 0;
                            while (aliases.ContainsKey(alias))
                            {
                                alias = cert.Subject + " #" + (++unique);
                            }
                            aliases.Add(alias, null);
                            jstore.setCertificateEntry(alias, cf.generateCertificate(new global::java.io.ByteArrayInputStream(cert.RawData)));
                        }
                    }
                    store.Close();
                    global::java.io.ByteArrayOutputStream baos = new global::java.io.ByteArrayOutputStream();
                    jstore.store(baos, new char[0]);
                    buf = baos.toByteArray();
                }
            }
示例#2
0
            private void Populate()
            {
                if (buf == null)
                {
#if NONMONOTOUCH
                    global::java.security.KeyStore jstore = global::java.security.KeyStore.getInstance("jks");
                    jstore.load(null);
                    global::java.security.cert.CertificateFactory cf = global::java.security.cert.CertificateFactory.getInstance("X509");

                    X509Store store = new X509Store(StoreName.Root, StoreLocation.LocalMachine);
                    store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
                    foreach (X509Certificate2 cert in store.Certificates)
                    {
                        if (!cert.HasPrivateKey)
                        {
                            jstore.setCertificateEntry(cert.Subject, cf.generateCertificate(new global::java.io.ByteArrayInputStream(cert.RawData)));
                        }
                    }
                    store.Close();
#endif
                    global::java.io.ByteArrayOutputStream baos = new global::java.io.ByteArrayOutputStream();
#if NONMONOTOUCH
                    jstore.store(baos, new char[0]);
#endif
                    buf = baos.toByteArray();
                }
            }