本文整理汇总了Java中java.security.cert.CertificateFactory类的典型用法代码示例。如果您正苦于以下问题:Java CertificateFactory类的具体用法?Java CertificateFactory怎么用?Java CertificateFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CertificateFactory类属于java.security.cert包,在下文中一共展示了CertificateFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getUserCertificate2
import java.security.cert.CertificateFactory; //导入依赖的package包/类
private static X509Certificate getUserCertificate2() throws Exception {
// this certificate does not include any extensions
String sCert =
"-----BEGIN CERTIFICATE-----\n"
+ "MIIBMjCB3aADAgECAhB6225ckZVssEukPuvk1U1PMA0GCSqGSIb3DQEBBAUAMBox\n"
+ "GDAWBgNVBAMTD1Jvb3RDZXJ0aWZpY2F0ZTAeFw0wMTEwMTkxNjA5NTZaFw0wMjEw\n"
+ "MTkyMjA5NTZaMBsxGTAXBgNVBAMTEFVzZXJDZXJ0aWZpY2F0ZTIwXDANBgkqhkiG\n"
+ "9w0BAQEFAANLADBIAkEAzicGiW9aUlUoQIZnLy1l8MMV5OvA+4VJ4T/xo/PpN8Oq\n"
+ "WgZVGKeEp6JCzMlXEJk3TGLfpXL4Ytw+Ldhv0QPhLwIDAnMpMA0GCSqGSIb3DQEB\n"
+ "BAUAA0EAQmj9SFHEx66JyAps3ew4pcSS3QvfVZ/6qsNUYCG75rFGcTUPHcXKql9y\n"
+ "qBT83iNLJ//krjw5Ju0WRPg/buHSww==\n"
+ "-----END CERTIFICATE-----";
CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
ByteArrayInputStream bytes = new ByteArrayInputStream(sCert.getBytes());
return (X509Certificate)certFactory.generateCertificate(bytes);
}
示例2: getCertificateFromStream
import java.security.cert.CertificateFactory; //导入依赖的package包/类
/**
* Generate Collection of Certificate from Input Stream
*
* @param stream InputStream of Certificate data
* @return Collection<X509Certificate>
* @throws PayPalRESTException
*/
@SuppressWarnings("unchecked")
public static Collection<X509Certificate> getCertificateFromStream(InputStream stream) throws PayPalRESTException {
if (stream == null) {
throw new PayPalRESTException("Certificate Not Found");
}
Collection<X509Certificate> certs = null;
try {
// Create a Certificate Factory
CertificateFactory cf = CertificateFactory.getInstance("X.509");
// Read the Trust Certs
certs = (Collection<X509Certificate>) cf.generateCertificates(stream);
} catch (CertificateException ex) {
throw new PayPalRESTException(ex);
}
return certs;
}
示例3: main
import java.security.cert.CertificateFactory; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
if (args.length == 0) {
System.out.println("Usage: java BlacklistedCertsConverter SHA-256" +
" < blacklisted.certs.pem > blacklisted.certs");
System.exit(1);
}
String mdAlg = args[0];
CertificateFactory cf = CertificateFactory.getInstance("X.509");
Collection<? extends Certificate> certs
= cf.generateCertificates(System.in);
System.out.println("Algorithm=" + mdAlg);
for (Certificate cert: certs) {
System.out.println(
getCertificateFingerPrint(mdAlg, (X509Certificate)cert));
}
}
示例4: getKeyFromConfigServer
import java.security.cert.CertificateFactory; //导入依赖的package包/类
private String getKeyFromConfigServer(RestTemplate keyUriRestTemplate) throws CertificateException {
// Load available UAA servers
discoveryClient.getServices();
HttpEntity<Void> request = new HttpEntity<Void>(new HttpHeaders());
String content = keyUriRestTemplate
.exchange("http://config/api/token_key", HttpMethod.GET, request, String.class).getBody();
if (StringUtils.isBlank(content)) {
throw new CertificateException("Received empty certificate from config.");
}
InputStream fin = new ByteArrayInputStream(content.getBytes());
CertificateFactory f = CertificateFactory.getInstance(Constants.CERTIFICATE);
X509Certificate certificate = (X509Certificate)f.generateCertificate(fin);
PublicKey pk = certificate.getPublicKey();
return String.format(Constants.PUBLIC_KEY, new String(Base64.encode(pk.getEncoded())));
}
示例5: readCertificateList
import java.security.cert.CertificateFactory; //导入依赖的package包/类
private List<Certificate> readCertificateList(BufferedSource source) throws IOException {
int length = readInt(source);
if (length == -1) return Collections.emptyList(); // OkHttp v1.2 used -1 to indicate null.
try {
CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
List<Certificate> result = new ArrayList<>(length);
for (int i = 0; i < length; i++) {
String line = source.readUtf8LineStrict();
Buffer bytes = new Buffer();
bytes.write(ByteString.decodeBase64(line));
result.add(certificateFactory.generateCertificate(bytes.inputStream()));
}
return result;
} catch (CertificateException e) {
throw new IOException(e.getMessage());
}
}
示例6: testCreateCRLException
import java.security.cert.CertificateFactory; //导入依赖的package包/类
@Test
public void testCreateCRLException() {
String crlfile = strFilePath + "/ssl/server.p12";
boolean validAssert = true;
try {
new MockUp<CertificateFactory>() {
@Mock
public final CertificateFactory getInstance(String type) throws CertificateException {
throw new CertificateException();
}
};
KeyStoreUtil.createCRL(crlfile);
} catch (Exception e) {
validAssert = false;
}
Assert.assertFalse(validAssert);
}
示例7: loadCert
import java.security.cert.CertificateFactory; //导入依赖的package包/类
private X509Certificate loadCert(Session session, long oHandle)
throws PKCS11Exception, CertificateException {
CK_ATTRIBUTE[] attrs = new CK_ATTRIBUTE[]
{ new CK_ATTRIBUTE(CKA_VALUE) };
token.p11.C_GetAttributeValue(session.id(), oHandle, attrs);
byte[] bytes = attrs[0].getByteArray();
if (bytes == null) {
throw new CertificateException
("unexpectedly retrieved null byte array");
}
CertificateFactory cf = CertificateFactory.getInstance("X.509");
return (X509Certificate)cf.generateCertificate
(new ByteArrayInputStream(bytes));
}
示例8: getX509Certificate
import java.security.cert.CertificateFactory; //导入依赖的package包/类
/**
* Method getX509Certificate
*
* @return the x509 certificate
* @throws XMLSecurityException
*/
public X509Certificate getX509Certificate() throws XMLSecurityException {
try {
byte certbytes[] = this.getCertificateBytes();
CertificateFactory certFact =
CertificateFactory.getInstance(XMLX509Certificate.JCA_CERT_ID);
X509Certificate cert =
(X509Certificate) certFact.generateCertificate(
new ByteArrayInputStream(certbytes)
);
if (cert != null) {
return cert;
}
return null;
} catch (CertificateException ex) {
throw new XMLSecurityException("empty", ex);
}
}
示例9: test
import java.security.cert.CertificateFactory; //导入依赖的package包/类
static void test(String... files) throws Exception {
try (FileOutputStream fout = new FileOutputStream(OUTFILE)) {
String here = System.getProperty("test.src", "");
for (String file: files) {
Files.copy(Paths.get(here, file), fout);
}
}
try (FileInputStream fin = new FileInputStream(OUTFILE)) {
System.out.println("Testing " + Arrays.toString(files) + "...");
if (CertificateFactory.getInstance("X509")
.generateCertificates(fin)
.size() != files.length) {
throw new Exception("Not same number");
}
}
Files.delete(Paths.get(OUTFILE));
}
示例10: getUserCertificate1
import java.security.cert.CertificateFactory; //导入依赖的package包/类
private static X509Certificate getUserCertificate1() throws Exception {
// this certificate includes an extension
String sCert =
"-----BEGIN CERTIFICATE-----\n"
+ "MIIBfzCCASmgAwIBAgIQWFSKzCWO2ptOAc2F3MKZSzANBgkqhkiG9w0BAQQFADAa\n"
+ "MRgwFgYDVQQDEw9Sb290Q2VydGlmaWNhdGUwHhcNMDExMDE5MTMwNzQxWhcNMzkx\n"
+ "MjMxMjM1OTU5WjAaMRgwFgYDVQQDEw9Vc2VyQ2VydGlmaWNhdGUwXDANBgkqhkiG\n"
+ "9w0BAQEFAANLADBIAkEA24gypa2YFGZHKznEWWbqIWNVXCM35W7RwJwhGpNsuBCj\n"
+ "NT6KEo66F+OOMgZmb0KrEZHBJASJ3n4Cqbt4aHm/2wIDAQABo0swSTBHBgNVHQEE\n"
+ "QDA+gBBch+eYzOPgVRbMq5vGpVWooRgwFjEUMBIGA1UEAxMLUm9vdCBBZ2VuY3mC\n"
+ "EMlg/HS1KKqSRcg8a30Za7EwDQYJKoZIhvcNAQEEBQADQQCYBIHBqQQJePi5Hzfo\n"
+ "CxeUaYlXmvbxVNkxM65Pplsj3h4ntfZaynmlhahH3YsnnA8wk6xPt04LjSId12RB\n"
+ "PeuO\n"
+ "-----END CERTIFICATE-----";
CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
ByteArrayInputStream bytes = new ByteArrayInputStream(sCert.getBytes());
return (X509Certificate)certFactory.generateCertificate(bytes);
}
示例11: PKCS12KeyStoreSpi
import java.security.cert.CertificateFactory; //导入依赖的package包/类
public PKCS12KeyStoreSpi(
Provider provider,
ASN1ObjectIdentifier keyAlgorithm,
ASN1ObjectIdentifier certAlgorithm)
{
this.keyAlgorithm = keyAlgorithm;
this.certAlgorithm = certAlgorithm;
try
{
if (provider != null)
{
certFact = CertificateFactory.getInstance("X.509", provider);
}
else
{
certFact = CertificateFactory.getInstance("X.509");
}
}
catch (Exception e)
{
throw new IllegalArgumentException("can't create cert factory - " + e.toString());
}
}
示例12: parseObject
import java.security.cert.CertificateFactory; //导入依赖的package包/类
/**
* Reads in a X509Certificate.
*
* @return the X509Certificate
* @throws IOException if an I/O error occured
*/
public Object parseObject(PemObject obj)
throws IOException
{
ByteArrayInputStream bIn = new ByteArrayInputStream(obj.getContent());
try
{
CertificateFactory certFact
= CertificateFactory.getInstance("X.509", provider);
return certFact.generateCertificate(bIn);
}
catch (Exception e)
{
throw new PEMException("problem parsing cert: " + e.toString(), e);
}
}
示例13: test_create_signature_x509_crt_crl
import java.security.cert.CertificateFactory; //导入依赖的package包/类
static void test_create_signature_x509_crt_crl() throws Exception {
System.out.println("* Generating signature-x509-crt-crl.xml");
List<Object> xds = new ArrayList<>();
CertificateFactory cf = CertificateFactory.getInstance("X.509");
xds.add(signingCert);
FileInputStream fis = new FileInputStream(CRL);
X509CRL crl = (X509CRL) cf.generateCRL(fis);
fis.close();
xds.add(crl);
KeyInfo crt_crl = kifac.newKeyInfo(Collections.singletonList
(kifac.newX509Data(xds)));
test_create_signature_external(dsaSha1, crt_crl, signingKey,
new X509KeySelector(ks), false);
System.out.println();
}
示例14: getKeyFromAuthorizationServer
import java.security.cert.CertificateFactory; //导入依赖的package包/类
private String getKeyFromAuthorizationServer(RestTemplate keyUriRestTemplate) throws CertificateException {
// Load available UAA servers
discoveryClient.getServices();
HttpEntity<Void> request = new HttpEntity<Void>(new HttpHeaders());
String content = keyUriRestTemplate
.exchange("http://config/api/token_key", HttpMethod.GET, request, String.class).getBody();
if (StringUtils.isBlank(content)) {
throw new CertificateException("Received empty certificate from config.");
}
InputStream fin = new ByteArrayInputStream(content.getBytes());
CertificateFactory f = CertificateFactory.getInstance(Constants.CERTIFICATE);
X509Certificate certificate = (X509Certificate)f.generateCertificate(fin);
PublicKey pk = certificate.getPublicKey();
return String.format(Constants.PUBLIC_KEY, new String(Base64.encode(pk.getEncoded())));
}
示例15: getTrustManager
import java.security.cert.CertificateFactory; //导入依赖的package包/类
private static X509TrustManager getTrustManager() throws Exception {
// generate certificate from cert string
CertificateFactory cf = CertificateFactory.getInstance("X.509");
// create a key store
KeyStore ks = KeyStore.getInstance("JKS");
ks.load(null, null);
// import the trusted cert
try (ByteArrayInputStream is =
new ByteArrayInputStream(trustedCertStr.getBytes())) {
Certificate trustedCert = cf.generateCertificate(is);
ks.setCertificateEntry("RSA Export Signer", trustedCert);
}
// create the trust manager
TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmAlgorithm);
tmf.init(ks);
return (X509TrustManager)tmf.getTrustManagers()[0];
}