本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
}
示例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()}));
}
}
}