本文整理了Java中java.security.cert.Certificate.toString()
方法的一些代码示例,展示了Certificate.toString()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Certificate.toString()
方法的具体详情如下:
包路径:java.security.cert.Certificate
类名称:Certificate
方法名:toString
[英]Returns a string containing a concise, human-readable description of the certificate.
[中]返回一个字符串,该字符串包含证书的简明易读描述。
代码示例来源:origin: skylot/jadx
public String generateText() {
StringBuilder str = new StringBuilder();
String type = cert.getType();
if (type.equals(CERTIFICATE_TYPE_NAME)) {
str.append(generateTextForX509());
} else {
str.append(cert.toString());
}
return str.toString();
}
代码示例来源:origin: robovm/robovm
/**
* Returns a string containing a concise, human-readable description of
* this {@code PrivateKeyEntry}.
*
* @return a printable representation for this {@code PrivateKeyEntry}.
*/
@Override
public String toString() {
StringBuilder sb = new StringBuilder(
"PrivateKeyEntry: number of elements in certificate chain is ");
sb.append(Integer.toString(chain.length));
sb.append("\n");
for (int i = 0; i < chain.length; i++) {
sb.append(chain[i].toString());
sb.append("\n");
}
return sb.toString();
}
}
代码示例来源:origin: stackoverflow.com
System.out.println("alias name: " + alias);
Certificate certificate = keystore.getCertificate(alias);
System.out.println(certificate.toString());
代码示例来源:origin: robovm/robovm
/**
* Returns a {@code String} representation of this {@code CertPath}
* instance. It is the result of calling {@code toString} on all {@code
* Certificate}s in the {@code List}.
*
* @return a string representation of this instance.
*/
public String toString() {
StringBuilder sb = new StringBuilder(getType());
sb.append(" Cert Path, len=");
sb.append(getCertificates().size());
sb.append(": [\n");
int n=1;
for (Iterator<? extends Certificate> i=getCertificates().iterator(); i.hasNext(); n++) {
sb.append("---------------certificate ");
sb.append(n);
sb.append("---------------\n");
sb.append(((Certificate)i.next()).toString());
}
sb.append("\n]");
return sb.toString();
}
代码示例来源:origin: hyperledger/fabric-sdk-java
boolean validateCertificate(Certificate cert) {
boolean isValidated;
if (cert == null) {
return false;
}
try {
KeyStore keyStore = getTrustStore();
PKIXParameters parms = new PKIXParameters(keyStore);
parms.setRevocationEnabled(false);
CertPathValidator certValidator = CertPathValidator.getInstance(CertPathValidator.getDefaultType()); // PKIX
ArrayList<Certificate> start = new ArrayList<>();
start.add(cert);
CertificateFactory certFactory = CertificateFactory.getInstance(CERTIFICATE_FORMAT);
CertPath certPath = certFactory.generateCertPath(start);
certValidator.validate(certPath, parms);
isValidated = true;
} catch (KeyStoreException | InvalidAlgorithmParameterException | NoSuchAlgorithmException
| CertificateException | CertPathValidatorException | CryptoException e) {
logger.error("Cannot validate certificate. Error is: " + e.getMessage() + "\r\nCertificate"
+ cert.toString());
isValidated = false;
}
return isValidated;
} // validateCertificate
代码示例来源:origin: hyperledger/fabric-sdk-java
if (config.extraLogLevel(10)) {
if (null != diagnosticFileDumper) {
logger.trace(format("Adding cert to trust store. alias: %s. certificate:", alias) + diagnosticFileDumper.createDiagnosticFile(alias + "cert: " + caCert.toString()));
代码示例来源:origin: stackoverflow.com
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
.....
private static String loadCertificate(String name) throws Exception {
CertificateFactory cf = CertificateFactory.getInstance("X509");
InputStream in = new FileInputStream(new File( name));
X509Certificate cert =(X509Certificate ) cf.generateCertificate(in);
in.close();
return cert.toString();
}
代码示例来源:origin: MobiVM/robovm
/**
* Returns a string containing a concise, human-readable description of
* this {@code PrivateKeyEntry}.
*
* @return a printable representation for this {@code PrivateKeyEntry}.
*/
@Override
public String toString() {
StringBuilder sb = new StringBuilder(
"PrivateKeyEntry: number of elements in certificate chain is ");
sb.append(Integer.toString(chain.length));
sb.append("\n");
for (int i = 0; i < chain.length; i++) {
sb.append(chain[i].toString());
sb.append("\n");
}
return sb.toString();
}
}
代码示例来源:origin: org.zaproxy/zap
/**
* Shows a second {@link JFrame} displaying the content of the certificate
*
* @param cert
*/
@SuppressWarnings("unused")
private void showCertificate(Certificate cert) {
if (cert != null) {
new CertificateView(cert.toString());
}
}
代码示例来源:origin: stackoverflow.com
try {
KeyStore ks = KeyStore.getInstance("AndroidCAStore");
ks.load(null);
try {
Enumeration<String> aliases = ks.aliases();
while (aliases.hasMoreElements()) {
Certificate cert = ks.getCertificate(aliases.nextElement());
Log.e(TAG, "Certificate: " + cert.toString());
}
}
catch(Exception e) {
e.printStackTrace();
}
}
catch (IOException|NoSuchAlgorithmException|KeyStoreException|CertificateException e) {
e.printStackTrace();
}
代码示例来源:origin: fernandospr/javapns-jdk16
private String getCertificateChainDescription() {
StringBuilder buf = new StringBuilder();
try {
SSLSession session = socket.getSession();
for (Certificate certificate : session.getLocalCertificates())
buf.append(certificate.toString());
buf.append("\n--------------------------------------------------------------------------\n");
for (X509Certificate certificate : session.getPeerCertificateChain())
buf.append(certificate.toString());
} catch (Exception e) {
buf.append(e);
}
return buf.toString();
}
代码示例来源:origin: mlaccetti/JavaPNS
private String getCertificateChainDescription() {
final StringBuilder buf = new StringBuilder();
try {
final SSLSession session = socket.getSession();
for (final Certificate certificate : session.getLocalCertificates()) {
buf.append(certificate.toString());
}
buf.append("\n--------------------------------------------------------------------------\n");
for (final X509Certificate certificate : session.getPeerCertificateChain()) {
buf.append(certificate.toString());
}
} catch (final Exception e) {
buf.append(e);
}
return buf.toString();
}
代码示例来源:origin: GoogleCloudPlatform/appengine-tck
private Exception createExceptionForLog(Exception e, int certNum, Certificate cert) {
return new Exception(e + ": certNum:" + certNum + " : " + cert.toString());
}
代码示例来源:origin: phax/as2-lib
@Nullable
public String getAlias (@Nullable final Certificate aCert) throws CertificateException
{
if (aCert == null)
return null;
try
{
return getKeyStore ().getCertificateAlias (aCert);
}
catch (final KeyStoreException kse)
{
throw new CertificateException ("Error getting alias for certificate: " + aCert.toString (), kse);
}
}
代码示例来源:origin: OpenAS2/OpenAs2App
protected CommandResult execute(AliasedCertificateFactory certFx,
Object[] params) throws OpenAS2Exception {
if (params.length < 1) {
return new CommandResult(CommandResult.TYPE_INVALID_PARAM_COUNT,
getUsage());
}
synchronized (certFx) {
String alias = params[0].toString();
Certificate cert = certFx.getCertificate(alias);
return new CommandResult(CommandResult.TYPE_OK, cert.toString());
}
}
}
代码示例来源:origin: palantir/conjure-java-runtime
@Test
public void testCreateTrustStoreFromCertificateDirectory() throws GeneralSecurityException, IOException {
File certFolder = tempFolder.newFolder();
Files.copy(TestConstants.CA_DER_CERT_PATH.toFile(), certFolder.toPath().resolve("ca.der").toFile());
Files.copy(TestConstants.SERVER_CERT_PEM_PATH.toFile(), certFolder.toPath().resolve("server.crt").toFile());
Files.copy(TestConstants.CLIENT_CERT_PEM_PATH.toFile(), certFolder.toPath().resolve("client.cer").toFile());
KeyStore trustStore = KeyStores.createTrustStoreFromCertificates(certFolder.toPath());
assertThat(trustStore.size(), is(3));
assertThat(trustStore.getCertificate("ca.der").toString(), containsString("CN=testCA"));
assertThat(trustStore.getCertificate("server.crt").toString(), containsString("CN=localhost"));
assertThat(trustStore.getCertificate("client.cer").toString(), containsString("CN=client"));
}
代码示例来源:origin: palantir/conjure-java-runtime
@Test
public void createTrustStoreFromCertificatesFromCertificatesByAlias() throws Exception {
String cert = Files.toString(TestConstants.SERVER_CERT_PEM_PATH.toFile(), StandardCharsets.UTF_8);
KeyStore trustStore = KeyStores.createTrustStoreFromCertificates(
ImmutableMap.of("server.crt", PemX509Certificate.of(cert)));
assertThat(trustStore.getCertificate("server.crt").toString(), containsString("CN=localhost"));
}
代码示例来源:origin: palantir/conjure-java-runtime
@Test
public void testCreateTrustStoreFromCertificateFile() throws GeneralSecurityException, IOException {
KeyStore trustStore = KeyStores.createTrustStoreFromCertificates(TestConstants.CA_DER_CERT_PATH);
assertThat(trustStore.size(), is(1));
assertThat(trustStore.getCertificate(TestConstants.CA_DER_CERT_PATH.getFileName().toString()).toString(),
containsString("CN=testCA"));
}
代码示例来源:origin: palantir/conjure-java-runtime
@Test
public void testCreateKeyStoreFromPemFile() throws GeneralSecurityException, IOException {
TestConstants.assumePkcs1ReaderExists();
String password = "changeit";
KeyStore keyStore = KeyStores.createKeyStoreFromCombinedPems(TestConstants.SERVER_KEY_CERT_COMBINED_PEM_PATH,
password);
assertThat(keyStore.size(), is(1));
assertThat(keyStore.getCertificate(
TestConstants.SERVER_KEY_CERT_COMBINED_PEM_PATH.getFileName().toString()).toString(),
containsString("CN=testCA"));
assertThat(keyStore.getKey(TestConstants.SERVER_KEY_CERT_COMBINED_PEM_PATH.getFileName().toString(),
password.toCharArray()).getFormat(),
is("PKCS#8"));
}
代码示例来源:origin: org.sonatype.nexus/nexus-core
@Override
protected String renderStatus() throws Exception {
return render(IdentityCapabilityDescriptor.TYPE_ID + "-status.vm", new TemplateParameters()
.set("nodeId", nodeAccess.getId())
.set("fingerprint", nodeAccess.getFingerprint())
.set("pem", CertificateUtil.serializeCertificateInPEM(nodeAccess.getCertificate()))
.set("detail", nodeAccess.getCertificate().toString())
);
}
}
内容来源于网络,如有侵权,请联系作者删除!