當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。