當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。