• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java X509V3CertificateGenerator类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.spongycastle.x509.X509V3CertificateGenerator的典型用法代码示例。如果您正苦于以下问题:Java X509V3CertificateGenerator类的具体用法?Java X509V3CertificateGenerator怎么用?Java X509V3CertificateGenerator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



X509V3CertificateGenerator类属于org.spongycastle.x509包,在下文中一共展示了X509V3CertificateGenerator类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: createCert

import org.spongycastle.x509.X509V3CertificateGenerator; //导入依赖的package包/类
private X509Certificate createCert() throws java.security.GeneralSecurityException {
    KeyPairGenerator generator = KeyPairGenerator.getInstance(KEY_PAIR_ALGORITHM);
    generator.initialize(ASYMMETRIC_KEY_SIZE);
    KeyPair keyPair = generator.generateKeyPair();

    //Check Certificate
    X509V3CertificateGenerator certGen = new X509V3CertificateGenerator();
    certGen.setSerialNumber(BigInteger.valueOf(1L));
    certGen.setSubjectDN(new X500Principal("CN=evs"));
    certGen.setIssuerDN(new X500Principal("CN=evs"));
    certGen.setPublicKey(keyPair.getPublic());
    certGen.setNotBefore(new Date());
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.YEAR, 100);
    certGen.setNotAfter(calendar.getTime());
    certGen.setSignatureAlgorithm(KEY_PAIR_SIGNING_ALGORITHM);
    return certGen.generate(keyPair.getPrivate());

}
 
开发者ID:SecureSmartHome,项目名称:SecureSmartHome,代码行数:20,代码来源:NamingManagerTest.java


示例2: generateCertificate

import org.spongycastle.x509.X509V3CertificateGenerator; //导入依赖的package包/类
/**
 * Generates a X509Certificate for the given keypair
 *
 * @param keyPair
 * @return
 */
private X509Certificate generateCertificate(KeyPair keyPair) {
    Calendar start = new GregorianCalendar();
    Calendar end = new GregorianCalendar();
    end.add(Calendar.YEAR, 200);
    X509V3CertificateGenerator cert = new X509V3CertificateGenerator();
    cert.setSerialNumber(BigInteger.ONE);   //or generate a random number
    cert.setSubjectDN(new X509Principal("CN=localhost"));  //see examples to add O,OU etc
    cert.setIssuerDN(new X509Principal("CN=localhost")); //same since it is self-signed
    cert.setPublicKey(keyPair.getPublic());
    cert.setNotBefore(start.getTime());
    cert.setNotAfter(end.getTime());
    cert.setSignatureAlgorithm("SHA1WithRSAEncryption");
    PrivateKey signingKey = keyPair.getPrivate();
    X509Certificate certChain = null;
    try {
        certChain = cert.generate(signingKey, "BC");
    } catch (CertificateEncodingException | NoSuchProviderException | NoSuchAlgorithmException | InvalidKeyException | SignatureException e) {
        ErrorLoggingSingleton log = ErrorLoggingSingleton.getInstance();
        log.storeError(ErrorLoggingSingleton.getExceptionStackTraceAsFormattedString(e));
        throw new RuntimeException(e);
    }

    return certChain;
}
 
开发者ID:timberdoodle,项目名称:TimberdoodleApp,代码行数:31,代码来源:PrivateKeyStore.java


示例3: generateCertificate

import org.spongycastle.x509.X509V3CertificateGenerator; //导入依赖的package包/类
public static X509Certificate generateCertificate(KeyPair pair)
        throws InvalidKeyException, NoSuchProviderException, SignatureException
{
    // generate the certificate
    X509V3CertificateGenerator certGen = new X509V3CertificateGenerator();

    certGen.setSerialNumber(BigInteger.valueOf(System.currentTimeMillis()));
    certGen.setIssuerDN(new X500Principal("CN=Restcomm Android SDK"));
    certGen.setNotBefore(new Date(System.currentTimeMillis() - 50000));
    // TODO: using 1 day for now, need to increase that
    certGen.setNotAfter(new Date(System.currentTimeMillis() + 86400000));
    certGen.setSubjectDN(new X500Principal("CN=Restcomm Android SDK"));
    certGen.setPublicKey(pair.getPublic());
    certGen.setSignatureAlgorithm("SHA1withECDSA");

    certGen.addExtension(X509Extensions.BasicConstraints, true, new BasicConstraints(false));
    certGen.addExtension(X509Extensions.KeyUsage, true, new KeyUsage(KeyUsage.digitalSignature | KeyUsage.keyEncipherment));
    certGen.addExtension(X509Extensions.ExtendedKeyUsage, true, new ExtendedKeyUsage(KeyPurposeId.id_kp_serverAuth));
    certGen.addExtension(X509Extensions.SubjectAlternativeName, false, new GeneralNames(new GeneralName(GeneralName.rfc822Name, "[email protected]")));

    // provider is Bouncy Castle
    return certGen.generateX509Certificate(pair.getPrivate(), "BC");
}
 
开发者ID:RestComm,项目名称:restcomm-android-sdk,代码行数:24,代码来源:JainSipSecurityHelper.java


示例4: createKey

import org.spongycastle.x509.X509V3CertificateGenerator; //导入依赖的package包/类
public static KeySet createKey( String keyAlgorithm, int keySize, String keyName,
                       String certSignatureAlgorithm, int certValidityYears, DistinguishedNameValues distinguishedNameValues)
{
    try {
        KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(keyAlgorithm);
        keyPairGenerator.initialize(keySize);
        KeyPair KPair = keyPairGenerator.generateKeyPair();

        X509V3CertificateGenerator v3CertGen = new X509V3CertificateGenerator();

        X509Principal principal = distinguishedNameValues.getPrincipal();

        // generate a postitive serial number
        BigInteger serialNumber = BigInteger.valueOf(new SecureRandom().nextInt());
        while (serialNumber.compareTo(BigInteger.ZERO) < 0) {
            serialNumber = BigInteger.valueOf(new SecureRandom().nextInt());
        }
        v3CertGen.setSerialNumber(serialNumber);
        v3CertGen.setIssuerDN( principal);
        v3CertGen.setNotBefore(new Date(System.currentTimeMillis() - 1000L * 60L * 60L * 24L * 30L));
        v3CertGen.setNotAfter(new Date(System.currentTimeMillis() + (1000L * 60L * 60L * 24L * 366L * (long)certValidityYears)));
        v3CertGen.setSubjectDN(principal);

        v3CertGen.setPublicKey(KPair.getPublic());
        v3CertGen.setSignatureAlgorithm(certSignatureAlgorithm);

        X509Certificate PKCertificate = v3CertGen.generate(KPair.getPrivate(),"BC");

        KeySet keySet = new KeySet();
        keySet.setName(keyName);
        keySet.setPrivateKey(KPair.getPrivate());
        keySet.setPublicKey(PKCertificate);
        return keySet;
    } catch (Exception x) {
        throw new RuntimeException(x.getMessage(), x);
    }
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:38,代码来源:CertCreator.java


示例5: createKey

import org.spongycastle.x509.X509V3CertificateGenerator; //导入依赖的package包/类
public static KeySet createKey(String keyAlgorithm, int keySize, String keyName,
                               String certSignatureAlgorithm, int certValidityYears, DistinguishedNameValues distinguishedNameValues) {
    try {
        KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance(keyAlgorithm);
        keyPairGenerator.initialize(keySize);
        KeyPair KPair = keyPairGenerator.generateKeyPair();

        X509V3CertificateGenerator v3CertGen = new X509V3CertificateGenerator();

        X509Principal principal = distinguishedNameValues.getPrincipal();

        // generate a postitive serial number
        BigInteger serialNumber = BigInteger.valueOf(new SecureRandom().nextInt());
        while (serialNumber.compareTo(BigInteger.ZERO) < 0) {
            serialNumber = BigInteger.valueOf(new SecureRandom().nextInt());
        }
        v3CertGen.setSerialNumber(serialNumber);
        v3CertGen.setIssuerDN(principal);
        v3CertGen.setNotBefore(new Date(System.currentTimeMillis() - 1000L * 60L * 60L * 24L * 30L));
        v3CertGen.setNotAfter(new Date(System.currentTimeMillis() + (1000L * 60L * 60L * 24L * 366L * (long) certValidityYears)));
        v3CertGen.setSubjectDN(principal);

        v3CertGen.setPublicKey(KPair.getPublic());
        v3CertGen.setSignatureAlgorithm(certSignatureAlgorithm);

        X509Certificate PKCertificate = v3CertGen.generate(KPair.getPrivate(), "BC");

        KeySet keySet = new KeySet();
        keySet.setName(keyName);
        keySet.setPrivateKey(KPair.getPrivate());
        keySet.setPublicKey(PKCertificate);
        return keySet;
    } catch (Exception x) {
        throw new RuntimeException(x.getMessage(), x);
    }
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:37,代码来源:CertCreator.java


示例6: generateV3Cert

import org.spongycastle.x509.X509V3CertificateGenerator; //导入依赖的package包/类
public static X509Certificate generateV3Cert(KeyPair pair) {

		X509Certificate cert = null;
		try {
			X509V3CertificateGenerator gen = new X509V3CertificateGenerator();
			gen.setPublicKey(pair.getPublic());
			gen.setSerialNumber(new BigInteger(Long.toString(System
					.currentTimeMillis() / 1000)));
			Hashtable attrs = new Hashtable();
			Vector vOrder = new Vector();
			attrs.put(X509Principal.CN, "[email protected]");
			vOrder.add(0, X509Principal.CN);
			attrs.put(X509Principal.OU, "self");
			vOrder.add(0, X509Principal.OU);
			attrs.put(X509Principal.O, "eBay, Inc.");
			vOrder.add(0, X509Principal.O);
			attrs.put(X509Principal.L, "San Jose");
			vOrder.add(0, X509Principal.L);
			attrs.put(X509Principal.ST, "California");
			vOrder.add(0, X509Principal.ST);
			attrs.put(X509Principal.C, "USA");
			vOrder.add(0, X509Principal.C);
			gen.setIssuerDN(new X509Principal(vOrder, attrs));
			gen.setSubjectDN(new X509Principal(vOrder, attrs));
			gen.setNotBefore(new Date(System.currentTimeMillis()));
			gen.setNotAfter(new Date(System.currentTimeMillis()
					+ VALIDITY_PERIOD));
			gen.setSignatureAlgorithm("SHA1WithECDSA");
			cert = gen.generate(pair.getPrivate(), "BC");

		} catch (Exception e) {
			System.out.println("Unable to generate a X509Certificate." + e);
		}
		return cert;
	}
 
开发者ID:zsavvas,项目名称:ReCRED_FIDO_UAF_OIDC,代码行数:36,代码来源:X509.java


示例7: testStoreKey

import org.spongycastle.x509.X509V3CertificateGenerator; //导入依赖的package包/类
/**
 * Test method for the initialization of the KeyStoreController
 *
 * @throws Exception
 */
public void testStoreKey() throws Exception {
    SimpleContainer container = new SimpleContainer();
    container.register(ContainerService.KEY_CONTEXT,
            new ContainerService.ContextComponent(getInstrumentation().getTargetContext()));
    KeyStoreController controller = new KeyStoreController();

    container.register(KEY, controller);

    KeyPairGenerator generator;

    generator = KeyPairGenerator.getInstance(KEY_PAIR_ALGORITHM);
    generator.initialize(ASYMMETRIC_KEY_SIZE);
    KeyPair keyPair = generator.generateKeyPair();

    //Check Certificate
    X509V3CertificateGenerator certGen = new X509V3CertificateGenerator();
    certGen.setSerialNumber(BigInteger.valueOf(1L));
    certGen.setSubjectDN(new X500Principal("CN=evs"));
    certGen.setIssuerDN(new X500Principal("CN=evs"));
    certGen.setPublicKey(keyPair.getPublic());
    certGen.setNotBefore(new Date());
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.YEAR, 100);
    certGen.setNotAfter(calendar.getTime());
    certGen.setSignatureAlgorithm(KEY_PAIR_SIGNING_ALGORITHM);
    X509Certificate cert = certGen.generate(keyPair.getPrivate());

    controller.saveCertificate(cert, "TestAlias");

    container.unregister(KEY);
    controller = new KeyStoreController();
    container.register(KEY, controller);

    assertTrue(Arrays.equals(controller.getCertificate("TestAlias").getEncoded(), cert.getEncoded()));
}
 
开发者ID:SecureSmartHome,项目名称:SecureSmartHome,代码行数:41,代码来源:KeyStoreControllerTest.java


示例8: generateAndStoreOwnKeyPair

import org.spongycastle.x509.X509V3CertificateGenerator; //导入依赖的package包/类
/**
 * Generates a KeyPair suited for asymmetric encryption.
 */
private void generateAndStoreOwnKeyPair() throws NoSuchAlgorithmException, KeyStoreException,
        CertificateException, SignatureException, InvalidKeyException {

    String keyPairAlgorithm;

    if (ASYMMETRIC_KEY_ALGORITHM.startsWith("EC") && ASYMMETRIC_KEY_ALGORITHM.length() > 2) {
        //Hardcoded Algorithms
        //see org.spongycastle.jcajce.provider.asymmetric.EC.Mappings.configure(ConfigurableProvider), line 52:
        //     "KeyPairGenerator.ECIES" -> "KeyPairGeneratorSpi$ECDH"
        keyPairAlgorithm = "EC";
        Log.w(KeyStoreController.class.getSimpleName(), "Using 'EC' instead of '" + keyPairAlgorithm
                + "' to circumvent wrong BouncyCastle mappings");
    } else {
        keyPairAlgorithm = ASYMMETRIC_KEY_ALGORITHM;
    }

    KeyPairGenerator generator;

    generator = KeyPairGenerator.getInstance(keyPairAlgorithm);
    generator.initialize(ASYMMETRIC_KEY_SIZE);

    KeyPair keyPair = generator.generateKeyPair();

    //Check Certificate
    X509V3CertificateGenerator certGen = new X509V3CertificateGenerator();
    certGen.setSerialNumber(BigInteger.valueOf(1L));
    certGen.setSubjectDN(new X500Principal("CN=evs"));
    certGen.setIssuerDN(new X500Principal("CN=evs"));
    certGen.setPublicKey(keyPair.getPublic());
    certGen.setNotBefore(new Date());
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.YEAR, 100);
    certGen.setNotAfter(calendar.getTime());
    certGen.setSignatureAlgorithm(ASYMMETRIC_SIGNING_ALGORITHM);
    X509Certificate cert = certGen.generate(keyPair.getPrivate());

    char[] keyPairPassword = getKeyPairPassword();
    keyStore.setEntry(LOCAL_PRIVATE_KEY_ALIAS,
            new KeyStore.PrivateKeyEntry(keyPair.getPrivate(), new X509Certificate[]{cert}),
            new KeyStore.PasswordProtection(keyPairPassword));
    Arrays.fill(keyPairPassword, (char) 0);

    try (FileOutputStream fileOutputStream = new FileOutputStream(keyStoreFile)) {
        keyStore.store(fileOutputStream, getKeystorePassword());
    } catch (IOException ex) {
        throw new KeyStoreException(ex);
    }
}
 
开发者ID:SecureSmartHome,项目名称:SecureSmartHome,代码行数:52,代码来源:KeyStoreController.java


示例9: doInBackground

import org.spongycastle.x509.X509V3CertificateGenerator; //导入依赖的package包/类
@Override
protected Void doInBackground(Void... arg0) {			
	Log.d("Cert Gen: ", "begin to generate");
	
       try {        	
   		// gen the RSA keypair
   		KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
   		keyPairGenerator.initialize(2048, new SecureRandom());
   		KeyPair KPair = keyPairGenerator.generateKeyPair();

   		// generate Certificate
   		X509V3CertificateGenerator v3CertGen = new X509V3CertificateGenerator();
   		
   		BigInteger serial = BigInteger.valueOf(new SecureRandom().nextInt());
   		String devicename = sharedPrefs.getString("device_name", "Device");
   		String deviceuuid = sharedPrefs.getString("uuid", "000000001111111");	    		

   		v3CertGen.setSerialNumber(serial.abs());
           v3CertGen.setIssuerDN(new X509Principal("CN=" + deviceuuid+"/" +devicename + ", OU=None, O=None L=None, C=None"));
           v3CertGen.setNotBefore(new Date(System.currentTimeMillis() - 1000L * 60 * 60 * 24 * 30));
           v3CertGen.setNotAfter(new Date(System.currentTimeMillis() + (1000L * 60 * 60 * 24 * 365*10)));
           v3CertGen.setSubjectDN(new X509Principal("CN=" + deviceuuid+"/" +devicename + ", OU=None, O=None L=None, C=None"));

           v3CertGen.setPublicKey(KPair.getPublic());
           v3CertGen.setSignatureAlgorithm("SHA256WithRSAEncryption");
           
           X509Certificate PKCertificate = v3CertGen.generate(KPair.getPrivate());	            
           
           // create keystore		
           InputStream keyStoreStream = getResources().openRawResource(R.raw.defaultkeystore);
   		
   		KeyStore MyKeyStore = KeyStore.getInstance("BKS");
   		MyKeyStore.load(keyStoreStream, "android".toCharArray());

   		Certificate[] certchain = new Certificate[1];
   		certchain[0] = PKCertificate;
   		
   		PrivateKey privkey = KPair.getPrivate();
   		MyKeyStore.setKeyEntry("mykeypair",privkey, "passwd".toCharArray(), certchain);
   		
   		// write new Keystore
   		OutputStream output = openFileOutput("devicekeystore.bks", Context.MODE_PRIVATE);

           MyKeyStore.store(output, "android".toCharArray());
           output.close();
           
       } catch (Exception e) {
         e.printStackTrace();
       }
       
	return null;
}
 
开发者ID:screenfreeze,项目名称:deskcon-android,代码行数:53,代码来源:MainActivity.java



注:本文中的org.spongycastle.x509.X509V3CertificateGenerator类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java UriBuilderException类代码示例发布时间:2022-05-21
下一篇:
Java InputDecryptorProvider类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap