本文整理汇总了Java中java.security.cert.CertPath.getEncoded方法的典型用法代码示例。如果您正苦于以下问题:Java CertPath.getEncoded方法的具体用法?Java CertPath.getEncoded怎么用?Java CertPath.getEncoded使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.security.cert.CertPath
的用法示例。
在下文中一共展示了CertPath.getEncoded方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import java.security.cert.CertPath; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
// Make the CertPath whose encoded form has already been stored
CertificateFactory certFac = CertificateFactory.getInstance("X509");
final List<Certificate> certs = new ArrayList<>();
certs.add(certFac.generateCertificate(new ByteArrayInputStream(cert1.getBytes())));
certs.add(certFac.generateCertificate(new ByteArrayInputStream(cert2.getBytes())));
CertPath cp = certFac.generateCertPath(certs);
// Get the encoded form of the CertPath we made
byte[] encoded = cp.getEncoded("PKCS7");
// check if it matches the encoded value
if (!Arrays.equals(encoded, Base64.getMimeDecoder().decode(pkcs7path.getBytes()))) {
throw new RuntimeException("PKCS#7 encoding doesn't match stored value");
}
// Generate a CertPath from the encoded value and check if it equals
// the CertPath generated from the certificates
CertPath decodedCP = certFac.generateCertPath(new ByteArrayInputStream(encoded), "PKCS7");
if (!decodedCP.equals(cp)) {
throw new RuntimeException("CertPath decoded from PKCS#7 isn't equal to original");
}
}
示例2: encodeX509CertChainToBase64
import java.security.cert.CertPath; //导入方法依赖的package包/类
/**
*
* 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;
}