当前位置: 首页>>代码示例>>Java>>正文


Java Certificate.equals方法代码示例

本文整理汇总了Java中java.security.cert.Certificate.equals方法的典型用法代码示例。如果您正苦于以下问题:Java Certificate.equals方法的具体用法?Java Certificate.equals怎么用?Java Certificate.equals使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.security.cert.Certificate的用法示例。


在下文中一共展示了Certificate.equals方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: engineGetCertificateAlias

import java.security.cert.Certificate; //导入方法依赖的package包/类
/**
 * Returns the (alias) name of the first keystore entry whose certificate
 * matches the given certificate.
 *
 * <p>This method attempts to match the given certificate with each
 * keystore entry. If the entry being considered
 * is a <i>trusted certificate entry</i>, the given certificate is
 * compared to that entry's certificate. If the entry being considered is
 * a <i>key entry</i>, the given certificate is compared to the first
 * element of that entry's certificate chain (if a chain exists).
 *
 * @param cert the certificate to match with.
 *
 * @return the (alias) name of the first entry with matching certificate,
 * or null if no such entry exists in this keystore.
 */
public String engineGetCertificateAlias(Certificate cert) {
    Certificate certElem;

    for (Enumeration<String> e = entries.keys(); e.hasMoreElements(); ) {
        String alias = e.nextElement();
        Object entry = entries.get(alias);
        if (entry instanceof TrustedCertEntry) {
            certElem = ((TrustedCertEntry)entry).cert;
        } else if (((KeyEntry)entry).chain != null) {
            certElem = ((KeyEntry)entry).chain[0];
        } else {
            continue;
        }
        if (certElem.equals(cert)) {
            return alias;
        }
    }
    return null;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:36,代码来源:JavaKeyStore.java

示例2: engineGetCertificateAlias

import java.security.cert.Certificate; //导入方法依赖的package包/类
/**
 * Returns the (alias) name of the first keystore entry whose certificate
 * matches the given certificate.
 *
 * <p>This method attempts to match the given certificate with each
 * keystore entry. If the entry being considered
 * is a <i>trusted certificate entry</i>, the given certificate is
 * compared to that entry's certificate. If the entry being considered is
 * a <i>key entry</i>, the given certificate is compared to the first
 * element of that entry's certificate chain (if a chain exists).
 *
 * @param cert the certificate to match with.
 *
 * @return the (alias) name of the first entry with matching certificate,
 * or null if no such entry exists in this keystore.
 */
public String engineGetCertificateAlias(Certificate cert) {
    Certificate certElem;

    Enumeration<String> e = entries.keys();
    while (e.hasMoreElements()) {
        String alias = e.nextElement();
        Object entry = entries.get(alias);
        if (entry instanceof TrustedCertEntry) {
            certElem = ((TrustedCertEntry)entry).cert;
        } else if ((entry instanceof PrivateKeyEntry) &&
                   (((PrivateKeyEntry)entry).chain != null)) {
            certElem = ((PrivateKeyEntry)entry).chain[0];
        } else {
            continue;
        }
        if (certElem.equals(cert)) {
            return alias;
        }
    }
    return null;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:38,代码来源:JceKeyStore.java

示例3: engineGetCertificateAlias

import java.security.cert.Certificate; //导入方法依赖的package包/类
/**
    * Returns the (alias) name of the first keystore entry whose certificate
 * matches the given certificate.
 *
 * <p>This method attempts to match the given certificate with each
 * keystore entry. If the entry being considered
 * is a <i>trusted certificate entry</i>, the given certificate is
 * compared to that entry's certificate. If the entry being considered is
 * a <i>key entry</i>, the given certificate is compared to the first
 * element of that entry's certificate chain (if a chain exists).
 *
 * @param cert the certificate to match with.
 *
 * @return the (alias) name of the first entry with matching certificate,
 * or null if no such entry exists in this keystore.
 */
public String engineGetCertificateAlias(Certificate cert) {
    permissionCheck();
    Certificate certElem;

    for (Enumeration e = entries.keys(); e.hasMoreElements(); ) {
        String alias = (String)e.nextElement();
        Object entry = entries.get(alias);
        if (entry instanceof TrustedCertEntry) {
            certElem = ((TrustedCertEntry)entry).cert;
        } else if (((KeyEntry)entry).chain != null) {
            certElem = ((KeyEntry)entry).chain[0];
        } else {
            continue;
        }
        if (certElem.equals(cert)) {
            return alias;
        }
    }
    return null;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:37,代码来源:KeychainStore.java

示例4: engineGetCertificateAlias

import java.security.cert.Certificate; //导入方法依赖的package包/类
/**
 * Returns the (alias) name of the first keystore entry whose certificate
 * matches the given certificate.
 *
 * <p>This method attempts to match the given certificate with each
 * keystore entry. If the entry being considered
 * is a <i>trusted certificate entry</i>, the given certificate is
 * compared to that entry's certificate. If the entry being considered is
 * a <i>key entry</i>, the given certificate is compared to the first
 * element of that entry's certificate chain (if a chain exists).
 *
 * @param cert the certificate to match with.
 *
 * @return the (alias) name of the first entry with matching certificate,
 * or null if no such entry exists in this keystore.
 */
public String engineGetCertificateAlias(Certificate cert) {
    Certificate certElem = null;

    for (Enumeration<String> e = engineAliases(); e.hasMoreElements(); ) {
        String alias = e.nextElement();
        Entry entry = entries.get(alias);
        if (entry instanceof PrivateKeyEntry) {
            if (((PrivateKeyEntry) entry).chain != null) {
                certElem = ((PrivateKeyEntry) entry).chain[0];
            }
        } else if (entry instanceof CertEntry &&
                ((CertEntry) entry).trustedKeyUsage != null) {
            certElem = ((CertEntry) entry).cert;
        } else {
            continue;
        }
        if (certElem != null && certElem.equals(cert)) {
            return alias;
        }
    }
    return null;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:39,代码来源:PKCS12KeyStore.java

示例5: runTest

import java.security.cert.Certificate; //导入方法依赖的package包/类
/**
 * Test logic (environment has set up)
 */
private void runTest() throws FileNotFoundException, CertificateException,
        KeyStoreException, IOException, NoSuchAlgorithmException {
    Certificate cert;
    CertificateFactory cf;
    try (FileInputStream fi = new FileInputStream(CERT_PATH)) {
        cf = CertificateFactory.getInstance("X.509");
        cert = cf.generateCertificate(fi);
        KeyStore ks = KeyStore.getInstance(
                Utils.KeyStoreType.pkcs12.name());
        ks.load(null, null);
        ks.setCertificateEntry(ALIAS, cert);
        Utils.saveKeyStore(ks, KEYSTORE_PATH, PASSWORD);
        ks = Utils.loadKeyStore(KEYSTORE_PATH, Utils.KeyStoreType.pkcs12,
                PASSWORD);
        final Certificate ksCert = ks.getCertificate(ALIAS);
        if (!ksCert.equals(cert)) {
            err.println("Orig cert: " + cert.toString());
            err.println("Cert from keystore: " + ksCert.toString());
            throw new RuntimeException("Certificates don't match");
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:26,代码来源:StoreTrustedCertAPITest.java

示例6: engineGetCertificateAlias

import java.security.cert.Certificate; //导入方法依赖的package包/类
/**
    * Returns the (alias) name of the first keystore entry whose certificate
 * matches the given certificate.
 *
 * <p>This method attempts to match the given certificate with each
 * keystore entry. If the entry being considered
 * is a <i>trusted certificate entry</i>, the given certificate is
 * compared to that entry's certificate. If the entry being considered is
 * a <i>key entry</i>, the given certificate is compared to the first
 * element of that entry's certificate chain (if a chain exists).
 *
 * @param cert the certificate to match with.
 *
 * @return the (alias) name of the first entry with matching certificate,
 * or null if no such entry exists in this keystore.
 */
public String engineGetCertificateAlias(Certificate cert) {
    permissionCheck();
    Certificate certElem;

    for (Enumeration<String> e = entries.keys(); e.hasMoreElements(); ) {
        String alias = e.nextElement();
        Object entry = entries.get(alias);
        if (entry instanceof TrustedCertEntry) {
            certElem = ((TrustedCertEntry)entry).cert;
        } else {
            KeyEntry ke = (KeyEntry)entry;
            if (ke.chain == null || ke.chain.length == 0) {
                continue;
            }
            certElem = ke.chain[0];
        }
        if (certElem.equals(cert)) {
            return alias;
        }
    }
    return null;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:39,代码来源:KeychainStore.java

示例7: isValidCertificate

import java.security.cert.Certificate; //导入方法依赖的package包/类
public synchronized boolean isValidCertificate(Certificate certificate,
        String host, int port) {
    if (mKeyStore == null) {
        return false;
    }
    Certificate storedCert = null;
    try {
        storedCert = mKeyStore.getCertificate(getCertKey(host, port));
        return (storedCert != null && storedCert.equals(certificate));
    } catch (KeyStoreException e) {
        return false;
    }
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:14,代码来源:LocalKeyStore.java

示例8: engineGetCertificateAlias

import java.security.cert.Certificate; //导入方法依赖的package包/类
public String engineGetCertificateAlias(Certificate cert)
{
    for (Iterator keys = trustedCerts.keySet().iterator(); keys.hasNext(); )
    {
        String alias = (String) keys.next();
        if (cert.equals(trustedCerts.get(alias)))
            return alias;
    }
    return null;
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:11,代码来源:JKS.java

示例9: engineGetCertificateAlias

import java.security.cert.Certificate; //导入方法依赖的package包/类
public String engineGetCertificateAlias(
    Certificate cert) 
{
    Enumeration e = table.elements();
    while (e.hasMoreElements())
    {
        StoreEntry  entry = (StoreEntry)e.nextElement();

        if (entry.getObject() instanceof Certificate)
        {
            Certificate c = (Certificate)entry.getObject();

            if (c.equals(cert))
            {
                return entry.getAlias();
            }
        }
        else
        {
            Certificate[]   chain = entry.getCertificateChain();

            if (chain != null && chain[0].equals(cert))
            {
                return entry.getAlias();
            }
        }
    }

    return null;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:31,代码来源:BcKeyStoreSpi.java

示例10: establishCertChain

import java.security.cert.Certificate; //导入方法依赖的package包/类
/**
 * Establishes a certificate chain (using trusted certificates in the
 * keystore), starting with the user certificate
 * and ending at a self-signed certificate found in the keystore.
 *
 * @param userCert the user certificate of the alias
 * @param certToVerify the single certificate provided in the reply
 */
private Certificate[] establishCertChain(Certificate userCert,
                                         Certificate certToVerify)
    throws Exception
{
    if (userCert != null) {
        // Make sure that the public key of the certificate reply matches
        // the original public key in the keystore
        PublicKey origPubKey = userCert.getPublicKey();
        PublicKey replyPubKey = certToVerify.getPublicKey();
        if (!origPubKey.equals(replyPubKey)) {
            throw new Exception(rb.getString
                    ("Public.keys.in.reply.and.keystore.don.t.match"));
        }

        // If the two certs are identical, we're done: no need to import
        // anything
        if (certToVerify.equals(userCert)) {
            throw new Exception(rb.getString
                    ("Certificate.reply.and.certificate.in.keystore.are.identical"));
        }
    }

    // Build a hash table of all certificates in the keystore.
    // Use the subject distinguished name as the key into the hash table.
    // All certificates associated with the same subject distinguished
    // name are stored in the same hash table entry as a vector.
    Hashtable<Principal, Vector<Certificate>> certs = null;
    if (keyStore.size() > 0) {
        certs = new Hashtable<Principal, Vector<Certificate>>(11);
        keystorecerts2Hashtable(keyStore, certs);
    }
    if (trustcacerts) {
        if (caks!=null && caks.size()>0) {
            if (certs == null) {
                certs = new Hashtable<Principal, Vector<Certificate>>(11);
            }
            keystorecerts2Hashtable(caks, certs);
        }
    }

    // start building chain
    Vector<Certificate> chain = new Vector<>(2);
    if (buildChain((X509Certificate)certToVerify, chain, certs)) {
        Certificate[] newChain = new Certificate[chain.size()];
        // buildChain() returns chain with self-signed root-cert first and
        // user-cert last, so we need to invert the chain before we store
        // it
        int j=0;
        for (int i=chain.size()-1; i>=0; i--) {
            newChain[j] = chain.elementAt(i);
            j++;
        }
        return newChain;
    } else {
        throw new Exception
            (rb.getString("Failed.to.establish.chain.from.reply"));
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:67,代码来源:Main.java

示例11: engineGetCertificateAlias

import java.security.cert.Certificate; //导入方法依赖的package包/类
@Override
public String engineGetCertificateAlias(Certificate cert) {
    return cert.equals(bazCert) ? baz : null;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:5,代码来源:DefineClass.java

示例12: engineGetCertificateAlias

import java.security.cert.Certificate; //导入方法依赖的package包/类
/**
 * Returns the (alias) name of the first keystore entry whose certificate
 * matches the given certificate.
 *
 * <p>This method attempts to match the given certificate with each
 * keystore entry. If the entry being considered was
 * created by a call to <code>setCertificateEntry</code>,
 * or created by a call to <code>setEntry</code> with a
 * <code>TrustedCertificateEntry</code>,
 * then the given certificate is compared to that entry's certificate.
 *
 * <p> If the entry being considered was
 * created by a call to <code>setKeyEntry</code>,
 * or created by a call to <code>setEntry</code> with a
 * <code>PrivateKeyEntry</code>,
 * then the given certificate is compared to the first
 * element of that entry's certificate chain.
 *
 * @param cert the certificate to match with.
 *
 * @return the alias name of the first entry with matching certificate,
 * or null if no such entry exists in this keystore.
 */
public synchronized String engineGetCertificateAlias(Certificate cert) {
    token.ensureValid();
    Enumeration<String> e = engineAliases();
    while (e.hasMoreElements()) {
        String alias = e.nextElement();
        Certificate tokenCert = engineGetCertificate(alias);
        if (tokenCert != null && tokenCert.equals(cert)) {
            return alias;
        }
    }
    return null;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:36,代码来源:P11KeyStore.java


注:本文中的java.security.cert.Certificate.equals方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。