本文整理汇总了Java中java.security.cert.CertificateFactory.generateCertificate方法的典型用法代码示例。如果您正苦于以下问题:Java CertificateFactory.generateCertificate方法的具体用法?Java CertificateFactory.generateCertificate怎么用?Java CertificateFactory.generateCertificate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.security.cert.CertificateFactory
的用法示例。
在下文中一共展示了CertificateFactory.generateCertificate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
示例2: runTest
import java.security.cert.CertificateFactory; //导入方法依赖的package包/类
/**
* Test logic (environment has set up)
*/
private void runTest() throws FileNotFoundException, CertificateException,
KeyStoreException, IOException, NoSuchAlgorithmException {
Certificate cert;
CertificateFactory cf;
try (FileInputStream fi = new FileInputStream(CERT_PATH)) {
cf = CertificateFactory.getInstance("X.509");
cert = cf.generateCertificate(fi);
KeyStore ks = KeyStore.getInstance(
Utils.KeyStoreType.pkcs12.name());
ks.load(null, null);
ks.setCertificateEntry(ALIAS, cert);
Utils.saveKeyStore(ks, KEYSTORE_PATH, PASSWORD);
ks = Utils.loadKeyStore(KEYSTORE_PATH, Utils.KeyStoreType.pkcs12,
PASSWORD);
final Certificate ksCert = ks.getCertificate(ALIAS);
if (!ksCert.equals(cert)) {
err.println("Orig cert: " + cert.toString());
err.println("Cert from keystore: " + ksCert.toString());
throw new RuntimeException("Certificates don't match");
}
}
}
示例3: 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);
}
示例4: isDebuggable
import java.security.cert.CertificateFactory; //导入方法依赖的package包/类
/**
* 检测当前应用是否是Debug版本
*
* @param ctx
* @return
*/
public static boolean isDebuggable(Context ctx) {
boolean debuggable = false;
try {
PackageInfo pinfo = ctx.getPackageManager().getPackageInfo(ctx.getPackageName(), PackageManager.GET_SIGNATURES);
Signature signatures[] = pinfo.signatures;
for (Signature signature : signatures) {
CertificateFactory cf = CertificateFactory.getInstance("X.509");
ByteArrayInputStream stream = new ByteArrayInputStream(signature.toByteArray());
X509Certificate cert = (X509Certificate) cf
.generateCertificate(stream);
debuggable = cert.getSubjectX500Principal().equals(DEBUG_DN);
if (debuggable)
break;
}
} catch (NameNotFoundException | CertificateException e) {
}
return debuggable;
}
示例5: 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));
}
示例6: createX509CertificateFromFile
import java.security.cert.CertificateFactory; //导入方法依赖的package包/类
private static X509Certificate createX509CertificateFromFile(
final String certificateFileName) throws IOException, CertificateException
{
// Load an X509 certificate from the specified certificate file name
final File file = new java.io.File(certificateFileName);
if (!file.isFile()) {
throw new IOException(
String.format("The certificate file %s doesn't exist.", certificateFileName));
}
final CertificateFactory certificateFactoryX509 = CertificateFactory.getInstance("X.509");
final InputStream inputStream = new FileInputStream(file);
final X509Certificate certificate = (X509Certificate) certificateFactoryX509.generateCertificate(inputStream);
inputStream.close();
return certificate;
}
开发者ID:PacktPublishing,项目名称:MQTT-Essentials-A-Lightweight-IoT-Protocol,代码行数:17,代码来源:SecurityHelper.java
示例7: addCertificate
import java.security.cert.CertificateFactory; //导入方法依赖的package包/类
private SSLSocketFactory addCertificate(InputStream inputStream) throws CertificateException, NoSuchAlgorithmException, IOException, KeyStoreException, KeyManagementException {
// loading CAs from an InputStream
CertificateFactory cf = CertificateFactory.getInstance("X.509");
Certificate ca;
try {
ca = cf.generateCertificate(inputStream);
} finally {
inputStream.close();
}
// creating a KeyStore containing our trusted CAs
String keyStoreType = KeyStore.getDefaultType();
KeyStore keyStore = KeyStore.getInstance(keyStoreType);
keyStore.load(null, null);
keyStore.setCertificateEntry("ca", ca);
// creating a TrustManager that trusts the CAs in our KeyStore
String tmfAlgorithm = TrustManagerFactory.getDefaultAlgorithm();
TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmfAlgorithm);
tmf.init(keyStore);
// creating an SSLSocketFactory that uses our TrustManager
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, tmf.getTrustManagers(), null);
return sslContext.getSocketFactory();
}
示例8: WriteP12Test
import java.security.cert.CertificateFactory; //导入方法依赖的package包/类
WriteP12Test() throws CertificateException {
CertificateFactory cf = CertificateFactory.getInstance("X.509");
caCert = cf.generateCertificate(new ByteArrayInputStream(CA_CERT_STR
.getBytes()));
testLeadCert = cf.generateCertificate(new ByteArrayInputStream(
LEAD_CERT.getBytes()));
testerCert = cf.generateCertificate(new ByteArrayInputStream(END_CERT
.getBytes()));
}
示例9: getCertificate
import java.security.cert.CertificateFactory; //导入方法依赖的package包/类
public static Certificate getCertificate(String certificatePath) throws Exception {
CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");
FileInputStream in = new FileInputStream(certificatePath);
Certificate certificate = certificateFactory.generateCertificate(in);
in.close();
return certificate;
}
示例10: readCert
import java.security.cert.CertificateFactory; //导入方法依赖的package包/类
private static Certificate readCert(DataInputStream in)
throws IOException, CertificateException, NoSuchAlgorithmException
{
String type = in.readUTF();
int len = in.readInt();
byte[] encoded = new byte[len];
in.read(encoded);
CertificateFactory factory = CertificateFactory.getInstance(type);
return factory.generateCertificate(new ByteArrayInputStream(encoded));
}
示例11: testCheckExpired
import java.security.cert.CertificateFactory; //导入方法依赖的package包/类
@Test(expected = CertificateException.class)
public void testCheckExpired() throws Exception {
final CertificateStoreX509TrustManager m = new CertificateStoreX509TrustManager(new TrustManagerHostnameCallback() {
@Override
public String getTarget() {
return "cyberduck.ch";
}
}, new DefaultCertificateStore());
CertificateFactory cf = CertificateFactory.getInstance("X.509");
X509Certificate cert = (X509Certificate) cf.generateCertificate(
new FileInputStream("src/test/resources//OXxlRDVcWqdPEvFm.cer")
);
m.checkServerTrusted(new X509Certificate[]{cert}, "RSA");
}
示例12: readCert
import java.security.cert.CertificateFactory; //导入方法依赖的package包/类
private X509Certificate readCert(String filename) throws IOException, CertificateException {
String fullPath = this.certDirectory + "/" + filename;
FileInputStream fis = new FileInputStream(fullPath);
CertificateFactory cf = CertificateFactory.getInstance("X.509");
X509Certificate cert = (X509Certificate) cf.generateCertificate(fis);
fis.close();
return cert;
}
示例13: loadX509Cert
import java.security.cert.CertificateFactory; //导入方法依赖的package包/类
public static X509Certificate loadX509Cert(String fileName) throws CertificateException, IOException {
CertificateFactory cf = CertificateFactory.getInstance("X.509");
InputStream in = SslUtil.class.getClassLoader().getResourceAsStream("certs/" + fileName);
try {
return (X509Certificate) cf.generateCertificate(in);
} finally {
in.close();
}
}
示例14: invoke
import java.security.cert.CertificateFactory; //导入方法依赖的package包/类
public void invoke(Request request, Response response)
throws IOException, ServletException {
/* mod_header converts the '\n' into ' ' so we have to rebuild the client certificate */
String strcert0 = mygetHeader(request, "ssl_client_cert");
if (strcert0 != null && strcert0.length()>28) {
String strcert1 = strcert0.replace(' ', '\n');
String strcert2 = strcert1.substring(28, strcert1.length()-26);
String strcert3 = new String("-----BEGIN CERTIFICATE-----\n");
String strcert4 = strcert3.concat(strcert2);
String strcerts = strcert4.concat("\n-----END CERTIFICATE-----\n");
// ByteArrayInputStream bais = new ByteArrayInputStream(strcerts.getBytes("UTF-8"));
ByteArrayInputStream bais = new ByteArrayInputStream(strcerts.getBytes());
X509Certificate jsseCerts[] = null;
try {
CertificateFactory cf = CertificateFactory.getInstance("X.509");
X509Certificate cert = (X509Certificate) cf.generateCertificate(bais);
jsseCerts = new X509Certificate[1];
jsseCerts[0] = cert;
} catch (java.security.cert.CertificateException e) {
System.out.println("SSLValve failed " + strcerts);
System.out.println("SSLValve failed " + e);
}
request.setAttribute("javax.servlet.request.X509Certificate", jsseCerts);
}
strcert0 = mygetHeader(request, "ssl_cipher");
if (strcert0 != null) {
request.setAttribute("javax.servlet.request.cipher_suite", strcert0);
}
strcert0 = mygetHeader(request, "ssl_session_id");
if (strcert0 != null) {
request.setAttribute("javax.servlet.request.ssl_session", strcert0);
}
strcert0 = mygetHeader(request, "ssl_cipher_usekeysize");
if (strcert0 != null) {
request.setAttribute("javax.servlet.request.key_size", strcert0);
}
getNext().invoke(request, response);
}
示例15: getCertificate
import java.security.cert.CertificateFactory; //导入方法依赖的package包/类
/**
* 获取CA证书信息
* @param cafile CA证书文件
* @return Certificate
* @throws CertificateException
* @throws IOException
*/
public static Certificate getCertificate(File cafile)
throws CertificateException, IOException {
CertificateFactory cf = CertificateFactory.getInstance("X.509");
FileInputStream in = new FileInputStream(cafile);
Certificate cert = cf.generateCertificate(in);
in.close();
return cert;
}