當前位置: 首頁>>代碼示例>>Java>>正文


Java Certificate.verify方法代碼示例

本文整理匯總了Java中java.security.cert.Certificate.verify方法的典型用法代碼示例。如果您正苦於以下問題:Java Certificate.verify方法的具體用法?Java Certificate.verify怎麽用?Java Certificate.verify使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.security.cert.Certificate的用法示例。


在下文中一共展示了Certificate.verify方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: test

import java.security.cert.Certificate; //導入方法依賴的package包/類
private static boolean test(Certificate target, Certificate signer,
        String title, boolean expected) throws Exception {
    System.out.print("Checking " + title + ": expected: " +
            (expected ? "    verified" : "NOT verified"));
    boolean actual;
    try {
        PublicKey pubKey = signer.getPublicKey();
        target.verify(pubKey);
        actual = true;
    } catch (SignatureException se) {
        actual = false;
    }
    System.out.println(", actual: " +
            (actual ? "    verified" : "NOT verified"));
    return actual == expected;
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:17,代碼來源:InvalidBitString.java

示例2: getTrustedSigner

import java.security.cert.Certificate; //導入方法依賴的package包/類
/**
 * Locates a signer for a given certificate from a given keystore and
 * returns the signer's certificate.
 * @param cert the certificate whose signer is searched, not null
 * @param ks the keystore to search with, not null
 * @return <code>cert</code> itself if it's already inside <code>ks</code>,
 * or a certificate inside <code>ks</code> who signs <code>cert</code>,
 * or null otherwise.
 */
private static Certificate getTrustedSigner(Certificate cert, KeyStore ks)
        throws Exception {
    if (ks.getCertificateAlias(cert) != null) {
        return cert;
    }
    for (Enumeration<String> aliases = ks.aliases();
            aliases.hasMoreElements(); ) {
        String name = aliases.nextElement();
        Certificate trustedCert = ks.getCertificate(name);
        if (trustedCert != null) {
            try {
                cert.verify(trustedCert.getPublicKey());
                return trustedCert;
            } catch (Exception e) {
                // Not verified, skip to the next one
            }
        }
    }
    return null;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:30,代碼來源:Main.java

示例3: getSigner

import java.security.cert.Certificate; //導入方法依賴的package包/類
/**
 * Locates a signer for a given certificate from a given keystore and
 * returns the signer's certificate.
 * @param cert the certificate whose signer is searched, not null
 * @param ks the keystore to search with, not null
 * @return <code>cert</code> itself if it's already inside <code>ks</code>,
 * or a certificate inside <code>ks</code> who signs <code>cert</code>,
 * or null otherwise. A label is added.
 */
private static Pair<String,Certificate>
        getSigner(Certificate cert, KeyStore ks) throws Exception {
    if (ks.getCertificateAlias(cert) != null) {
        return new Pair<>("", cert);
    }
    for (Enumeration<String> aliases = ks.aliases();
            aliases.hasMoreElements(); ) {
        String name = aliases.nextElement();
        Certificate trustedCert = ks.getCertificate(name);
        if (trustedCert != null) {
            try {
                cert.verify(trustedCert.getPublicKey());
                return new Pair<>(name, trustedCert);
            } catch (Exception e) {
                // Not verified, skip to the next one
            }
        }
    }
    return null;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:30,代碼來源:Main.java

示例4: verifyCertificate

import java.security.cert.Certificate; //導入方法依賴的package包/類
private static boolean verifyCertificate(
        final KeyStore store,
        final Certificate certificate) throws KeyStoreException {
    for (String alias : Collections.list(store.aliases())) {
        try {
            certificate.verify(store.getCertificate(alias).getPublicKey());
            return true;
        } catch (GeneralSecurityException e) {
            // we must ignore this exception as it is VERY expected -- will
            // happen N-1 times at least
        }
    }

    return false;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:16,代碼來源:SecurityUtils.java

示例5: verifyZip

import java.security.cert.Certificate; //導入方法依賴的package包/類
public static boolean verifyZip(String zipPath, Certificate remoteCertificate) {
    try {
        String certPath = checkZipFileForCertificate(zipPath);
        Certificate certificate = getCertificateFromZip(zipPath, certPath);
        remoteCertificate.verify(certificate.getPublicKey());
        return true;
    } catch (Exception e) {
        e.printStackTrace();
        return false;
    }
}
 
開發者ID:didi,項目名稱:VirtualAPK,代碼行數:12,代碼來源:ZipVerifyUtil.java

示例6: getAndVerifyEntry

import java.security.cert.Certificate; //導入方法依賴的package包/類
private static JarEntry getAndVerifyEntry(JarFile jar, String name, PublicKey key) throws IOException, GeneralSecurityException {
    JarEntry entry = jar.getJarEntry(name);
    if(entry == null) {
        return null;
    } else {
        byte[] buffer = new byte[1024];
        InputStream certificates = jar.getInputStream(entry);
        Throwable lastException = null;

        try {
            while(true) {
                if(certificates.read(buffer) > 0) {
                    break;
                }
            }
        } catch (Throwable var20) {
            lastException = var20;
            throw var20;
        } finally {
            if(certificates != null) {
                if(lastException != null) {
                    try {
                        certificates.close();
                    } catch (Throwable var18) {
                        lastException.addSuppressed(var18);
                    }
                } else {
                    certificates.close();
                }
            }

        }

        Certificate[] var22 = entry.getCertificates();
        if(var22 != null && var22.length != 0) {
            GeneralSecurityException var23 = null;
            boolean verified = false;
            Certificate[] var8 = var22;
            int var9 = var22.length;
            int var10 = 0;

            while(var10 < var9) {
                Certificate certificate = var8[var10];

                try {
                    certificate.verify(key);
                    verified = true;
                    break;
                } catch (GeneralSecurityException var19) {
                    var23 = var19;
                    ++var10;
                }
            }

            if(!verified) {
                throw var23;
            } else {
                return entry;
            }
        } else {
            throw new GeneralSecurityException(String.format("JAR \'%s\' is unsigned!", new Object[]{jar.getName()}));
        }
    }
}
 
開發者ID:transwarpio,項目名稱:rapidminer,代碼行數:65,代碼來源:JarVerifier.java


注:本文中的java.security.cert.Certificate.verify方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。