本文整理汇总了Java中org.spongycastle.cert.jcajce.JcaX509v3CertificateBuilder类的典型用法代码示例。如果您正苦于以下问题:Java JcaX509v3CertificateBuilder类的具体用法?Java JcaX509v3CertificateBuilder怎么用?Java JcaX509v3CertificateBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JcaX509v3CertificateBuilder类属于org.spongycastle.cert.jcajce包,在下文中一共展示了JcaX509v3CertificateBuilder类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: initialiseCertificate
import org.spongycastle.cert.jcajce.JcaX509v3CertificateBuilder; //导入依赖的package包/类
static void initialiseCertificate(Context c, KeyPair keyPair){
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DAY_OF_MONTH, -1);
Date notBefore = calendar.getTime();
calendar.add(Calendar.YEAR, 10);
Date notAfter = calendar.getTime();
X500NameBuilder nameBuilder = new X500NameBuilder(BCStyle.INSTANCE);
nameBuilder.addRDN(BCStyle.CN, "an2linuxclient");
nameBuilder.addRDN(BCStyle.SERIALNUMBER, new BigInteger(128, new Random()).toString(16));
X509v3CertificateBuilder certificateBuilder = new JcaX509v3CertificateBuilder(
nameBuilder.build(),
BigInteger.ONE,
notBefore, notAfter,
nameBuilder.build(),
keyPair.getPublic()
);
try {
ContentSigner contentSigner = new JcaContentSignerBuilder("SHA256WithRSAEncryption").setProvider("BC").build(keyPair.getPrivate());
X509Certificate certificate = new JcaX509CertificateConverter().setProvider("BC").getCertificate(certificateBuilder.build(contentSigner));
SharedPreferences deviceKeyPref = c.getSharedPreferences(
c.getString(R.string.device_key_and_cert), MODE_PRIVATE);
deviceKeyPref.edit().putString(c.getString(R.string.certificate),
Base64.encodeToString(certificate.getEncoded(), Base64.NO_WRAP)).apply();
Log.d("TlsHelper", "Generated new certificate successfully");
} catch (Exception e){
Log.e("TlsHelper", "initialiseCertificate");
Log.e("StackTrace", Log.getStackTraceString(e));
}
}
开发者ID:rootkiwi,项目名称:an2linuxclient,代码行数:33,代码来源:TlsHelper.java
示例2: generateSignedCertificate
import org.spongycastle.cert.jcajce.JcaX509v3CertificateBuilder; //导入依赖的package包/类
public static X509Certificate generateSignedCertificate(X509Certificate caCertificate, PrivateKey caPrivateKey, PublicKey publicKey, String CN)
throws NoSuchAlgorithmException, OperatorCreationException, CertificateException,
KeyStoreException, UnrecoverableKeyException, IOException,
InvalidKeyException, NoSuchPaddingException, InvalidParameterSpecException,
InvalidKeySpecException, InvalidAlgorithmParameterException, IllegalBlockSizeException,
BadPaddingException {
X500NameBuilder builder = new X500NameBuilder(BCStyle.INSTANCE);
builder.addRDN(BCStyle.CN, CN);
// We want this root certificate to be valid for one year
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.YEAR, 1);
ContentSigner sigGen = new JcaContentSignerBuilder("SHA1WithRSAEncryption").setProvider(BC).build(caPrivateKey);
X509v3CertificateBuilder certGen = new JcaX509v3CertificateBuilder(
caCertificate,
new BigInteger(80, new Random()),
new Date(System.currentTimeMillis() - 50000),
calendar.getTime(),
new X500Principal(builder.build().getEncoded()),
publicKey);
// Those are the extensions needed for the certificate to be a leaf certificate that authenticates a SSL server
certGen.addExtension(new ASN1ObjectIdentifier("2.5.29.15"), true, new X509KeyUsage(X509KeyUsage.keyEncipherment));
certGen.addExtension(new ASN1ObjectIdentifier("2.5.29.37"), true, new DERSequence(KeyPurposeId.id_kp_serverAuth));
X509CertificateHolder certificateHolder = certGen.build(sigGen);
X509Certificate certificate = new JcaX509CertificateConverter().setProvider(BC).getCertificate(certificateHolder);
return certificate;
}
开发者ID:ghazi94,项目名称:Android_CCTV,代码行数:35,代码来源:ModSSL.java
示例3: generateRootCertificate
import org.spongycastle.cert.jcajce.JcaX509v3CertificateBuilder; //导入依赖的package包/类
public static X509Certificate generateRootCertificate(KeyPair keys, String CN)
throws NoSuchAlgorithmException, OperatorCreationException, CertificateException,
KeyStoreException, UnrecoverableKeyException, IOException,
InvalidKeyException, NoSuchPaddingException, InvalidParameterSpecException,
InvalidKeySpecException, InvalidAlgorithmParameterException, IllegalBlockSizeException,
BadPaddingException {
X500NameBuilder builder = new X500NameBuilder(BCStyle.INSTANCE);
builder.addRDN(BCStyle.CN, CN);
// We want this root certificate to be valid for one year
Calendar calendar = Calendar.getInstance();
calendar.add( Calendar.YEAR, 1 );
ContentSigner sigGen = new JcaContentSignerBuilder("SHA1WithRSAEncryption").setProvider(BC).build(keys.getPrivate());
X509v3CertificateBuilder certGen = new JcaX509v3CertificateBuilder(
builder.build(),
new BigInteger(80, new Random()),
new Date(System.currentTimeMillis() - 50000),
calendar.getTime(),
builder.build(),
keys.getPublic());
// Those are the extensions needed for a CA certificate
certGen.addExtension(new ASN1ObjectIdentifier("2.5.29.19"), true, new BasicConstraints(true));
certGen.addExtension(new ASN1ObjectIdentifier("2.5.29.15"), true, new X509KeyUsage(X509KeyUsage.digitalSignature));
certGen.addExtension(new ASN1ObjectIdentifier("2.5.29.37"), true, new ExtendedKeyUsage(KeyPurposeId.id_kp_serverAuth));
X509CertificateHolder certificateHolder = certGen.build(sigGen);
X509Certificate certificate = new JcaX509CertificateConverter().setProvider(BC).getCertificate(certificateHolder);
return certificate;
}
开发者ID:ghazi94,项目名称:Android_CCTV,代码行数:37,代码来源:ModSSL.java
示例4: generateSelfSignedCertificate
import org.spongycastle.cert.jcajce.JcaX509v3CertificateBuilder; //导入依赖的package包/类
public static void generateSelfSignedCertificate() throws Exception {
String alias = "nuntius";
KeyStore ks = KeyStore.getInstance("AndroidKeyStore");
ks.load(null);
Enumeration<String> aliases = ks.aliases();
boolean found = false;
while (aliases.hasMoreElements()) {
String currentAlias = aliases.nextElement();
if (alias.equals(currentAlias)) {
found = true;
Log.i(TAG, "Self Signed Certificate found in keystore");
Key key = ks.getKey(alias, pwd);
Log.i(TAG, "Key: " + key);
Certificate certificate = ks.getCertificate(alias);
Log.i(TAG, "Certificate: " + certificate);
}
}
if (found) {
return;
}
Log.i(TAG, "Self Signed Certificate not found in keystore. Generating a new one...");
KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
keyGen.initialize(1024);
KeyPair keyPair = keyGen.generateKeyPair();
X500Name subject = new X500Name("CN=nuntius");
X500Name issuer = subject ;
X509v3CertificateBuilder builder = new JcaX509v3CertificateBuilder(
issuer,
new BigInteger(64, new SecureRandom()),
NOT_BEFORE,
NOT_AFTER,
subject,
keyPair.getPublic());
ContentSigner signer = new JcaContentSignerBuilder("SHA256WithRSAEncryption").build(keyPair.getPrivate());
X509CertificateHolder certHolder = builder.build(signer);
X509Certificate cert = new JcaX509CertificateConverter().setProvider(PROVIDER).getCertificate(certHolder);
cert.verify(keyPair.getPublic());
Log.i(TAG, "Certificate generated: " + cert);
ks.setKeyEntry(alias, keyPair.getPrivate(), pwd, new Certificate[] { cert });
}
开发者ID:RomascuAndrei,项目名称:BTNotifierAndroid,代码行数:49,代码来源:SslUtils.java
注:本文中的org.spongycastle.cert.jcajce.JcaX509v3CertificateBuilder类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论