java.security.cert.CertPath.getEncoded()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(11.8k)|赞(0)|评价(0)|浏览(176)

本文整理了Java中java.security.cert.CertPath.getEncoded()方法的一些代码示例,展示了CertPath.getEncoded()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。CertPath.getEncoded()方法的具体详情如下:
包路径:java.security.cert.CertPath
类名称:CertPath
方法名:getEncoded

CertPath.getEncoded介绍

[英]Returns an encoding of the CertPath using the default encoding.
[中]返回使用默认编码的CertPath编码。

代码示例

代码示例来源:origin: robovm/robovm

/**
 * Returns an alternate object to be serialized.
 *
 * @return an alternate object to be serialized.
 * @throws ObjectStreamException
 *             if the creation of the alternate object fails.
 */
protected Object writeReplace() throws ObjectStreamException {
  try {
    return new CertPathRep(getType(), getEncoded());
  } catch (CertificateEncodingException e) {
    throw new NotSerializableException("Could not create serialization object: " + e);
  }
}

代码示例来源:origin: wildfly/wildfly

@Override
public void engineSetKeyEntry(String alias, byte[] keystoreBytes, Certificate[] chain) throws KeyStoreException {
  try {
    List<ModificationItem> items = new LinkedList<>();
    items.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute(keyAttribute, keystoreBytes)));
    CertificateFactory certFactory = CertificateFactory.getInstance(certificateType);
    CertPath certPath = certFactory.generateCertPath(Arrays.asList(chain));
    BasicAttribute chainAttr = new BasicAttribute(certificateChainAttribute, certPath.getEncoded(certificateChainEncoding));
    items.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE, chainAttr));
    BasicAttribute certificateAttr = new BasicAttribute(certificateAttribute, chain[0].getEncoded());
    items.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE, certificateAttr));
    storeAttributes(alias, items);
  } catch (CertificateException e) {
    throw log.ldapKeyStoreFailedToSerializeCertificate(alias, e);
  }
}

代码示例来源:origin: eclipse/californium

/**
 * Gets a binary representation of this certificate chain using the <em>PkiPath</em> encoding.
 * 
 * @return The binary encoding.
 */
public byte[] toByteArray() {
  try {
    return path.getEncoded("PkiPath");
  } catch (CertificateEncodingException e) {
    // should not happen because all Java 7 implementations are required to
    // support PkiPath encoding of X.509 certificates
    return new byte[0];
  }
}

代码示例来源:origin: ZZMarquis/gmhelper

public static byte[] getCertificateChainBytes(CertPath certChain) throws CertificateEncodingException {
  return certChain.getEncoded("PKCS7");
}

代码示例来源:origin: com.xqbase/tuna-mux

private static byte[] encodeCerts(Certificate[] certs) {
  if (certs == null) {
    return Bytes.EMPTY_BYTES;
  }
  try {
    return CertificateFactory.getInstance("X509").
        generateCertPath(Arrays.asList(certs)).getEncoded("PKCS7");
  } catch (GeneralSecurityException e) {
    return Bytes.EMPTY_BYTES;
  }
}

代码示例来源:origin: stackoverflow.com

X509Certificate newCert =
     certGen.generateX509Certificate(privateKey, "BC");
   //=============================
   List chain = new ArrayList();
   chain.add(newCert);
   //-------------------------------------------------
   //  create the CertPath with old BouncyCastle
   CertificateFactory fact =
     CertificateFactory.getInstance("X.509", "BC");
   CertPath path = fact.generateCertPath(chain);
   result = Base64Utils.base64Encode(path.getEncoded("PKCS7"));

代码示例来源:origin: demoiselle/certificate

/**
 * @return ASN.1 DER encoded on Base64, for X.509 certificate *
 */
public static String encodeX509CertChainToBase64(Certificate[] aCertificationChain) throws CertificateException {
  List<Certificate> certList = Arrays.asList(aCertificationChain);
  CertificateFactory certFactory = CertificateFactory.getInstance(X509_CERTIFICATE_TYPE);
  CertPath certPath = certFactory.generateCertPath(certList);
  byte[] certPathEncoded = certPath.getEncoded(CERTIFICATION_CHAIN_ENCODING);
  String base64encodedCertChain = Base64Utils.base64Encode(certPathEncoded);
  return base64encodedCertChain;
}

代码示例来源:origin: org.demoiselle.signer/signature-core

/**
 *
 * Efetua a codificação de uma cadeia de certificados para a base 64
 *
 * @param aCertificationChain A cadeia de certificados
 * @return ASN.1 DER encoded on Base64, for X.509 certificate
 * @throws CertificateException Lança a exceção
 */
public static String encodeX509CertChainToBase64(Certificate[] aCertificationChain) throws CertificateException {
  List<Certificate> certList = Arrays.asList(aCertificationChain);
  CertificateFactory certFactory = CertificateFactory.getInstance(X509_CERTIFICATE_TYPE);
  CertPath certPath = certFactory.generateCertPath(certList);
  byte[] certPathEncoded = certPath.getEncoded(CERTIFICATION_CHAIN_ENCODING);
  String base64encodedCertChain = Base64Utils.base64Encode(certPathEncoded);
  return base64encodedCertChain;
}

代码示例来源:origin: MobiVM/robovm

/**
 * Returns an alternate object to be serialized.
 *
 * @return an alternate object to be serialized.
 * @throws ObjectStreamException
 *             if the creation of the alternate object fails.
 */
protected Object writeReplace() throws ObjectStreamException {
  try {
    return new CertPathRep(getType(), getEncoded());
  } catch (CertificateEncodingException e) {
    throw new NotSerializableException("Could not create serialization object: " + e);
  }
}

代码示例来源:origin: ibinti/bugvm

/**
 * Returns an alternate object to be serialized.
 *
 * @return an alternate object to be serialized.
 * @throws ObjectStreamException
 *             if the creation of the alternate object fails.
 */
protected Object writeReplace() throws ObjectStreamException {
  try {
    return new CertPathRep(getType(), getEncoded());
  } catch (CertificateEncodingException e) {
    throw new NotSerializableException("Could not create serialization object: " + e);
  }
}

代码示例来源:origin: com.mobidevelop.robovm/robovm-rt

/**
 * Returns an alternate object to be serialized.
 *
 * @return an alternate object to be serialized.
 * @throws ObjectStreamException
 *             if the creation of the alternate object fails.
 */
protected Object writeReplace() throws ObjectStreamException {
  try {
    return new CertPathRep(getType(), getEncoded());
  } catch (CertificateEncodingException e) {
    throw new NotSerializableException("Could not create serialization object: " + e);
  }
}

代码示例来源:origin: org.demoiselle.signer/core

/**
 *
 * Performs the encoding of a certificate chain to base64
 *
 * @param aCertificationChain certificate chain
 * @return ASN.1 DER encoded on Base64, for X.509 certificate
 * @throws CertificateException exception
 */
public static String encodeX509CertChainToBase64(Certificate[] aCertificationChain) throws CertificateException {
  List<Certificate> certList = Arrays.asList(aCertificationChain);
  CertificateFactory certFactory = CertificateFactory.getInstance(X509_CERTIFICATE_TYPE);
  CertPath certPath = certFactory.generateCertPath(certList);
  byte[] certPathEncoded = certPath.getEncoded(CERTIFICATION_CHAIN_ENCODING);
  String base64encodedCertChain = Base64Utils.base64Encode(certPathEncoded);
  return base64encodedCertChain;
}

代码示例来源:origin: com.bugvm/bugvm-rt

/**
 * Returns an alternate object to be serialized.
 *
 * @return an alternate object to be serialized.
 * @throws ObjectStreamException
 *             if the creation of the alternate object fails.
 */
protected Object writeReplace() throws ObjectStreamException {
  try {
    return new CertPathRep(getType(), getEncoded());
  } catch (CertificateEncodingException e) {
    throw new NotSerializableException("Could not create serialization object: " + e);
  }
}

代码示例来源:origin: FlexoVM/flexovm

/**
 * Returns an alternate object to be serialized.
 *
 * @return an alternate object to be serialized.
 * @throws ObjectStreamException
 *             if the creation of the alternate object fails.
 */
protected Object writeReplace() throws ObjectStreamException {
  try {
    return new CertPathRep(getType(), getEncoded());
  } catch (CertificateEncodingException e) {
    throw new NotSerializableException("Could not create serialization object: " + e);
  }
}

代码示例来源:origin: com.gluonhq/robovm-rt

/**
 * Returns an alternate object to be serialized.
 *
 * @return an alternate object to be serialized.
 * @throws ObjectStreamException
 *             if the creation of the alternate object fails.
 */
protected Object writeReplace() throws ObjectStreamException {
  try {
    return new CertPathRep(getType(), getEncoded());
  } catch (CertificateEncodingException e) {
    throw new NotSerializableException("Could not create serialization object: " + e);
  }
}

代码示例来源:origin: kaikramer/keystore-explorer

/**
 * PKI Path encode a number of certificates.
 *
 * @return The encoding
 * @param certs
 *            The certificates
 * @throws CryptoException
 *             If there was a problem encoding the certificates
 */
public static byte[] getCertsEncodedPkiPath(X509Certificate[] certs) throws CryptoException {
  try {
    ArrayList<Certificate> encodedCerts = new ArrayList<>();
    Collections.addAll(encodedCerts, certs);
    CertificateFactory cf = CertificateFactory.getInstance(X509_CERT_TYPE, BOUNCY_CASTLE.jce());
    CertPath cp = cf.generateCertPath(encodedCerts);
    return cp.getEncoded(PKI_PATH_ENCODING);
  } catch (CertificateException | NoSuchProviderException e) {
    throw new CryptoException(res.getString("NoPkcs7Encode.exception.message"), e);
  }
}

代码示例来源:origin: apache/incubator-wave

private byte[] calculateSignerId(List<? extends X509Certificate> certs)
   throws SignatureException {
  try {
   CertificateFactory certFactory = CertificateFactory.getInstance(X509);
   CertPath path = certFactory.generateCertPath(certs);
   byte[] encodedCertPath = path.getEncoded(PKI_PATH_ENCODING);
   MessageDigest digest = MessageDigest.getInstance(
     AlgorithmUtil.getJceName(getHashAlgorithm()));
   return digest.digest(encodedCertPath);

  } catch (CertificateException e) {
   throw new SignatureException("could not parse certificate chain", e);
  } catch (NoSuchAlgorithmException e) {
   throw new SignatureException("could not calculate hash of cert chain", e);
  }
 }
}

代码示例来源:origin: org.wildfly.security/wildfly-elytron-credential

@Override
public void engineSetKeyEntry(String alias, byte[] keystoreBytes, Certificate[] chain) throws KeyStoreException {
  try {
    List<ModificationItem> items = new LinkedList<>();
    items.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute(keyAttribute, keystoreBytes)));
    CertificateFactory certFactory = CertificateFactory.getInstance(certificateType);
    CertPath certPath = certFactory.generateCertPath(Arrays.asList(chain));
    BasicAttribute chainAttr = new BasicAttribute(certificateChainAttribute, certPath.getEncoded(certificateChainEncoding));
    items.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE, chainAttr));
    BasicAttribute certificateAttr = new BasicAttribute(certificateAttribute, chain[0].getEncoded());
    items.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE, certificateAttr));
    storeAttributes(alias, items);
  } catch (CertificateException e) {
    throw log.ldapKeyStoreFailedToSerializeCertificate(alias, e);
  }
}

代码示例来源:origin: org.wildfly.security/wildfly-elytron

@Override
public void engineSetKeyEntry(String alias, byte[] keystoreBytes, Certificate[] chain) throws KeyStoreException {
  try {
    List<ModificationItem> items = new LinkedList<>();
    items.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute(keyAttribute, keystoreBytes)));
    CertificateFactory certFactory = CertificateFactory.getInstance(certificateType);
    CertPath certPath = certFactory.generateCertPath(Arrays.asList(chain));
    BasicAttribute chainAttr = new BasicAttribute(certificateChainAttribute, certPath.getEncoded(certificateChainEncoding));
    items.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE, chainAttr));
    BasicAttribute certificateAttr = new BasicAttribute(certificateAttribute, chain[0].getEncoded());
    items.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE, certificateAttr));
    storeAttributes(alias, items);
  } catch (CertificateException e) {
    throw log.ldapKeyStoreFailedToSerializeCertificate(alias, e);
  }
}

代码示例来源:origin: org.jboss.eap/wildfly-client-all

@Override
public void engineSetKeyEntry(String alias, byte[] keystoreBytes, Certificate[] chain) throws KeyStoreException {
  try {
    List<ModificationItem> items = new LinkedList<>();
    items.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute(keyAttribute, keystoreBytes)));
    CertificateFactory certFactory = CertificateFactory.getInstance(certificateType);
    CertPath certPath = certFactory.generateCertPath(Arrays.asList(chain));
    BasicAttribute chainAttr = new BasicAttribute(certificateChainAttribute, certPath.getEncoded(certificateChainEncoding));
    items.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE, chainAttr));
    BasicAttribute certificateAttr = new BasicAttribute(certificateAttribute, chain[0].getEncoded());
    items.add(new ModificationItem(DirContext.REPLACE_ATTRIBUTE, certificateAttr));
    storeAttributes(alias, items);
  } catch (CertificateException e) {
    throw log.ldapKeyStoreFailedToSerializeCertificate(alias, e);
  }
}

相关文章