当前位置: 首页>>代码示例>>Java>>正文


Java BouncyCastleProvider类代码示例

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


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

示例1: generate

import org.bouncycastle.jce.provider.BouncyCastleProvider; //导入依赖的package包/类
public X509Certificate generate(String dn, KeyPair keyPair) throws CertificateException {
    try {
        Security.addProvider(new BouncyCastleProvider());
        AlgorithmIdentifier sigAlgId = new DefaultSignatureAlgorithmIdentifierFinder().find(algorithm);
        AlgorithmIdentifier digAlgId = new DefaultDigestAlgorithmIdentifierFinder().find(sigAlgId);
        AsymmetricKeyParameter privateKeyAsymKeyParam = PrivateKeyFactory.createKey(keyPair.getPrivate().getEncoded());
        SubjectPublicKeyInfo subPubKeyInfo = SubjectPublicKeyInfo.getInstance(keyPair.getPublic().getEncoded());
        ContentSigner sigGen = new BcRSAContentSignerBuilder(sigAlgId, digAlgId).build(privateKeyAsymKeyParam);
        X500Name name = new X500Name(dn);
        Date from = new Date();
        Date to = new Date(from.getTime() + days * 86400000L);
        BigInteger sn = new BigInteger(64, new SecureRandom());
        X509v3CertificateBuilder v3CertGen = new X509v3CertificateBuilder(name, sn, from, to, name, subPubKeyInfo);

        if (subjectAltName != null)
            v3CertGen.addExtension(Extension.subjectAlternativeName, false, subjectAltName);
        X509CertificateHolder certificateHolder = v3CertGen.build(sigGen);
        return new JcaX509CertificateConverter().setProvider("BC").getCertificate(certificateHolder);
    } catch (CertificateException ce) {
        throw ce;
    } catch (Exception e) {
        throw new CertificateException(e);
    }
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:25,代码来源:TestSslUtils.java

示例2: getSocketFactory

import org.bouncycastle.jce.provider.BouncyCastleProvider; //导入依赖的package包/类
private SSLSocketFactory getSocketFactory() {
  try {
    Security.addProvider(new BouncyCastleProvider());

    TrustManagerFactory trustManagerFactory = createAndInitTrustManagerFactory();
    KeyManagerFactory keyManagerFactory = createAndInitKeyManagerFactory();

    SSLContext context = SSLContext.getInstance(TLS_VERSION);
    context.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), null);

    return context.getSocketFactory();
  } catch (Exception e) {
    log.error("[{}:{}:{}:{}] Creating TLS factory failed!", caCert, cert, privateKey, password, e);
    throw new RuntimeException("Creating TLS factory failed!", e);
  }
}
 
开发者ID:osswangxining,项目名称:iotgateway,代码行数:17,代码来源:CertPemClientCredentials.java

示例3: verifySignature

import org.bouncycastle.jce.provider.BouncyCastleProvider; //导入依赖的package包/类
public static boolean verifySignature(CMSSignedData cmsSignedData, X509Certificate cert) {
    try {
        if (Security.getProvider("BC") == null)
            Security.addProvider(new BouncyCastleProvider());

        Collection<SignerInformation> signers = cmsSignedData.getSignerInfos().getSigners();
        X509CertificateHolder ch = new X509CertificateHolder(cert.getEncoded());
        for (SignerInformation si : signers)
            if (si.getSID().match(ch))
                if (si.verify(new JcaSimpleSignerInfoVerifierBuilder().setProvider("BC").build(ch)))
                    return true;
    } catch (Exception e) {}
    return false;
}
 
开发者ID:damianofalcioni,项目名称:Websocket-Smart-Card-Signer,代码行数:15,代码来源:PKCS7Manager.java

示例4: verifyUserSig

import org.bouncycastle.jce.provider.BouncyCastleProvider; //导入依赖的package包/类
@Override
public boolean verifyUserSig(String identifier, String sig)throws QCloudException {
	try {
		Security.addProvider(new BouncyCastleProvider());
		
		//DeBaseUrl64 urlSig to json
		Base64 decoder = new Base64();

		byte [] compressBytes = Base64Url.base64DecodeUrl(sig.getBytes(Charset.forName("UTF-8")));
		
		//Decompression
		Inflater decompression =  new Inflater();
		decompression.setInput(compressBytes, 0, compressBytes.length);
		byte [] decompressBytes = new byte [1024];
		int decompressLength = decompression.inflate(decompressBytes);
		decompression.end();
		
		String jsonString = new String(Arrays.copyOfRange(decompressBytes, 0, decompressLength));
		
		//Get TLS.Sig from json
		JSONObject jsonObject= JSON.parseObject(jsonString);
		String sigTLS = jsonObject.getString("TLS.sig");
		
		//debase64 TLS.Sig to get serailString
		byte[] signatureBytes = decoder.decode(sigTLS.getBytes(Charset.forName("UTF-8")));
		
		String strSdkAppid = jsonObject.getString("TLS.sdk_appid");
		String sigTime = jsonObject.getString("TLS.time");
		String sigExpire = jsonObject.getString("TLS.expire_after");
		
		if (!imConfig.getSdkAppId().equals(strSdkAppid))
		{
			return false;
		}

		if ( System.currentTimeMillis()/1000 - Long.parseLong(sigTime) > Long.parseLong(sigExpire)) {
			return false;
		}
		
		//Get Serial String from json
		String SerialString = 
			"TLS.appid_at_3rd:" + 0 + "\n" +
			"TLS.account_type:" + 0 + "\n" +
			"TLS.identifier:" + identifier + "\n" + 
			"TLS.sdk_appid:" + imConfig.getSdkAppId() + "\n" + 
			"TLS.time:" + sigTime + "\n" + 
			"TLS.expire_after:" + sigExpire + "\n";
	
        Reader reader = new CharArrayReader(imConfig.getPublicKey().toCharArray());
        PEMParser  parser = new PEMParser(reader);
        JcaPEMKeyConverter converter = new JcaPEMKeyConverter();
        Object obj = parser.readObject();
        parser.close();
        PublicKey pubKeyStruct  = converter.getPublicKey((SubjectPublicKeyInfo) obj);

		Signature signature = Signature.getInstance("SHA256withECDSA","BC");
		signature.initVerify(pubKeyStruct);
		signature.update(SerialString.getBytes(Charset.forName("UTF-8")));
		return signature.verify(signatureBytes);
	}catch (Exception e) {
		throw new QCloudException(e);
	}
}
 
开发者ID:51wakeup,项目名称:wakeup-qcloud-sdk,代码行数:64,代码来源:DefaultQCloudClient.java

示例5: makePBECipher

import org.bouncycastle.jce.provider.BouncyCastleProvider; //导入依赖的package包/类
protected Cipher makePBECipher(
    String  algorithm,
    int     mode,
    char[]  password,
    byte[]  salt,
    int     iterationCount)
    throws IOException
{
    try
    {
        PBEKeySpec          pbeSpec = new PBEKeySpec(password);
        SecretKeyFactory    keyFact = SecretKeyFactory.getInstance(algorithm, BouncyCastleProvider.PROVIDER_NAME);
        PBEParameterSpec    defParams = new PBEParameterSpec(salt, iterationCount);

        Cipher cipher = Cipher.getInstance(algorithm, BouncyCastleProvider.PROVIDER_NAME);

        cipher.init(mode, keyFact.generateSecret(pbeSpec), defParams);

        return cipher;
    }
    catch (Exception e)
    {
        throw new IOException("Error initialising store of key store: " + e);
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:26,代码来源:BcKeyStoreSpi.java

示例6: addBcProvider

import org.bouncycastle.jce.provider.BouncyCastleProvider; //导入依赖的package包/类
private void addBcProvider() {
    final String provName = "BC";
    if (Security.getProvider(provName) != null) {
        LOG.info("security provider {} already initialized by other service", provName);
        return;
    }
    Security.addProvider(new BouncyCastleProvider());
}
 
开发者ID:xipki,项目名称:xitk,代码行数:9,代码来源:Providers.java

示例7: getSocketFactory

import org.bouncycastle.jce.provider.BouncyCastleProvider; //导入依赖的package包/类
private SSLSocketFactory getSocketFactory() {
    try {
        Security.addProvider(new BouncyCastleProvider());

        TrustManagerFactory trustManagerFactory = createAndInitTrustManagerFactory();
        KeyManagerFactory keyManagerFactory = createAndInitKeyManagerFactory();

        SSLContext context = SSLContext.getInstance(TLS_VERSION);
        context.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), null);

        return context.getSocketFactory();
    } catch (Exception e) {
        log.error("[{}:{}:{}:{}] Creating TLS factory failed!", caCert, cert, privateKey, password, e);
        throw new RuntimeException("Creating TLS factory failed!", e);
    }
}
 
开发者ID:thingsboard,项目名称:thingsboard-gateway,代码行数:17,代码来源:CertPemClientCredentials.java

示例8: BCDSTU4145PublicKey

import org.bouncycastle.jce.provider.BouncyCastleProvider; //导入依赖的package包/类
public BCDSTU4145PublicKey(
    org.bouncycastle.jce.spec.ECPublicKeySpec spec)
{
    this.q = spec.getQ();

    if (spec.getParams() != null) // can be null if implictlyCa
    {
        ECCurve curve = spec.getParams().getCurve();
        EllipticCurve ellipticCurve = EC5Util.convertCurve(curve, spec.getParams().getSeed());

        this.ecSpec = EC5Util.convertSpec(ellipticCurve, spec.getParams());
    }
    else
    {
        if (q.getCurve() == null)
        {
            org.bouncycastle.jce.spec.ECParameterSpec s = BouncyCastleProvider.CONFIGURATION.getEcImplicitlyCa();

            q = s.getCurve().createPoint(q.getX().toBigInteger(), q.getY().toBigInteger(), false);
        }
        this.ecSpec = null;
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:24,代码来源:BCDSTU4145PublicKey.java

示例9: verify

import org.bouncycastle.jce.provider.BouncyCastleProvider; //导入依赖的package包/类
public final void verify(
    PublicKey   key)
    throws CertificateException, NoSuchAlgorithmException,
    InvalidKeyException, NoSuchProviderException, SignatureException
{
    Signature   signature;
    String      sigName = X509SignatureUtil.getSignatureName(c.getSignatureAlgorithm());
    
    try
    {
        signature = Signature.getInstance(sigName, BouncyCastleProvider.PROVIDER_NAME);
    }
    catch (Exception e)
    {
        signature = Signature.getInstance(sigName);
    }
    
    checkSignature(key, signature);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:20,代码来源:X509CertificateObject.java

示例10: engineGeneratePrivate

import org.bouncycastle.jce.provider.BouncyCastleProvider; //导入依赖的package包/类
protected PrivateKey engineGeneratePrivate(
    KeySpec keySpec)
    throws InvalidKeySpecException
{
    if (keySpec instanceof PKCS8EncodedKeySpec)
    {
        try
        {
            PrivateKeyInfo info = PrivateKeyInfo.getInstance(((PKCS8EncodedKeySpec)keySpec).getEncoded());
            PrivateKey     key = BouncyCastleProvider.getPrivateKey(info);

            if (key != null)
            {
                return key;
            }

            throw new InvalidKeySpecException("no factory found for OID: " + info.getPrivateKeyAlgorithm().getAlgorithm());
        }
        catch (Exception e)
        {
            throw new InvalidKeySpecException(e.toString());
        }
    }

    throw new InvalidKeySpecException("Unknown KeySpec type: " + keySpec.getClass().getName());
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:27,代码来源:KeyFactory.java

示例11: engineGeneratePublic

import org.bouncycastle.jce.provider.BouncyCastleProvider; //导入依赖的package包/类
protected PublicKey engineGeneratePublic(
    KeySpec keySpec)
    throws InvalidKeySpecException
{
    if (keySpec instanceof X509EncodedKeySpec)
    {
        try
        {
            SubjectPublicKeyInfo info = SubjectPublicKeyInfo.getInstance(((X509EncodedKeySpec)keySpec).getEncoded());
            PublicKey            key = BouncyCastleProvider.getPublicKey(info);

            if (key != null)
            {
                return key;
            }

            throw new InvalidKeySpecException("no factory found for OID: " + info.getAlgorithm().getAlgorithm());
        }
        catch (Exception e)
        {
            throw new InvalidKeySpecException(e.toString());
        }
    }

    throw new InvalidKeySpecException("Unknown KeySpec type: " + keySpec.getClass().getName());
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:27,代码来源:KeyFactory.java

示例12: engineInitVerify

import org.bouncycastle.jce.provider.BouncyCastleProvider; //导入依赖的package包/类
protected void engineInitVerify(
    PublicKey   publicKey)
    throws InvalidKeyException
{
    CipherParameters    param;

    if (publicKey instanceof ECPublicKey)
    {
        param = ECUtil.generatePublicKeyParameter(publicKey);
    }
    else if (publicKey instanceof GOST3410Key)
    {
        param = GOST3410Util.generatePublicKeyParameter(publicKey);
    }
    else
    {
        try
        {
            byte[]  bytes = publicKey.getEncoded();

            publicKey = BouncyCastleProvider.getPublicKey(SubjectPublicKeyInfo.getInstance(bytes));

            if (publicKey instanceof ECPublicKey)
            {
                param = ECUtil.generatePublicKeyParameter(publicKey);
            }
            else
            {
                throw new InvalidKeyException("can't recognise key type in DSA based signer");
            }
        }
        catch (Exception e)
        {
            throw new InvalidKeyException("can't recognise key type in DSA based signer");
        }
    }

    digest.reset();
    signer.init(false, param);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:41,代码来源:SignatureSpi.java

示例13: engineGetParameters

import org.bouncycastle.jce.provider.BouncyCastleProvider; //导入依赖的package包/类
public AlgorithmParameters engineGetParameters()
{
    if (engineParam == null && engineSpec != null)
    {
        try
        {
            engineParam = AlgorithmParameters.getInstance("IES", BouncyCastleProvider.PROVIDER_NAME);
            engineParam.init(engineSpec);
        }
        catch (Exception e)
        {
            throw new RuntimeException(e.toString());
        }
    }

    return engineParam;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:18,代码来源:IESCipher.java

示例14: engineGetParameters

import org.bouncycastle.jce.provider.BouncyCastleProvider; //导入依赖的package包/类
protected AlgorithmParameters engineGetParameters()
{
    if (engineParams == null)
    {
        if (paramSpec != null)
        {
            try
            {
                engineParams = AlgorithmParameters.getInstance("PSS", BouncyCastleProvider.PROVIDER_NAME);
                engineParams.init(paramSpec);
            }
            catch (Exception e)
            {
                throw new RuntimeException(e.toString());
            }
        }
    }

    return engineParams;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:21,代码来源:PSSSignatureSpi.java

示例15: setup

import org.bouncycastle.jce.provider.BouncyCastleProvider; //导入依赖的package包/类
/**
 * Ensure that BouncyCastleProvider is registered.
 */
@BeforeClass
public static void setup() {
  if (Security.getProvider("BC") == null) {
    Security.addProvider(new BouncyCastleProvider());
  }
}
 
开发者ID:mit-ll,项目名称:PACE,代码行数:10,代码来源:EntryEncryptorTest.java


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