当前位置: 首页>>代码示例>>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;未经允许,请勿转载。