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


Java AsymmetricKeyParameter类代码示例

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


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

示例1: generate

import org.bouncycastle.crypto.params.AsymmetricKeyParameter; //导入依赖的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: generatePublicKeyParameter

import org.bouncycastle.crypto.params.AsymmetricKeyParameter; //导入依赖的package包/类
static public AsymmetricKeyParameter generatePublicKeyParameter(
    PublicKey key)
    throws InvalidKeyException
{
    if (key instanceof BCMcElieceCCA2PublicKey)
    {
        BCMcElieceCCA2PublicKey k = (BCMcElieceCCA2PublicKey)key;

        return new McElieceCCA2PublicKeyParameters(k.getOIDString(), k.getN(), k.getT(), k.getG(), k.getMcElieceCCA2Parameters());
    }

    throw new InvalidKeyException("can't identify McElieceCCA2 public key: " + key.getClass().getName());
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:14,代码来源:McElieceCCA2KeysToParams.java

示例3: build

import org.bouncycastle.crypto.params.AsymmetricKeyParameter; //导入依赖的package包/类
public ContentVerifierProvider build(final AsymmetricKeyParameter publicKey)
    throws OperatorCreationException
{
    return new ContentVerifierProvider()
    {
        public boolean hasAssociatedCertificate()
        {
            return false;
        }

        public X509CertificateHolder getAssociatedCertificate()
        {
            return null;
        }

        public ContentVerifier get(AlgorithmIdentifier algorithm)
            throws OperatorCreationException
        {
            BcSignerOutputStream stream = createSignatureStream(algorithm, publicKey);

            return new SigVerifier(algorithm, stream);
        }
    };
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:25,代码来源:BcContentVerifierProviderBuilder.java

示例4: receiveCertificateVerifyMessage

import org.bouncycastle.crypto.params.AsymmetricKeyParameter; //导入依赖的package包/类
protected void receiveCertificateVerifyMessage(ByteArrayInputStream buf)
    throws IOException
{

    byte[] clientCertificateSignature = TlsUtils.readOpaque16(buf);

    assertEmpty(buf);

    // Verify the CertificateVerify message contains a correct signature.
    try
    {
        TlsSigner tlsSigner = TlsUtils.createTlsSigner(this.clientCertificateType);
        tlsSigner.init(getContext());

        org.bouncycastle.asn1.x509.Certificate x509Cert = this.clientCertificate.getCertificateAt(0);
        SubjectPublicKeyInfo keyInfo = x509Cert.getSubjectPublicKeyInfo();
        AsymmetricKeyParameter publicKey = PublicKeyFactory.createKey(keyInfo);

        tlsSigner.verifyRawSignature(clientCertificateSignature, publicKey, this.certificateVerifyHash);
    }
    catch (Exception e)
    {
        throw new TlsFatalAlert(AlertDescription.decrypt_error);
    }
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:26,代码来源:TlsServerProtocol.java

示例5: generateCertificate

import org.bouncycastle.crypto.params.AsymmetricKeyParameter; //导入依赖的package包/类
/**
 * Create a self-signed X.509 Certificate.
 * From http://bfo.com/blog/2011/03/08/odds_and_ends_creating_a_new_x_509_certificate.html.
 *
 * @param dn        the X.509 Distinguished Name, eg "CN=Test, L=London, C=GB"
 * @param pair      the KeyPair
 * @param days      how many days from now the Certificate is valid for
 * @param algorithm the signing algorithm, eg "SHA1withRSA"
 * @return the self-signed certificate
 * @throws CertificateException thrown if a security error or an IO error occurred.
 */
public static X509Certificate generateCertificate(String dn, KeyPair pair,
                                                  int days, String algorithm)
    throws CertificateException {

  try {
    Security.addProvider(new BouncyCastleProvider());
    AlgorithmIdentifier sigAlgId = new DefaultSignatureAlgorithmIdentifierFinder().find(algorithm);
    AlgorithmIdentifier digAlgId = new DefaultDigestAlgorithmIdentifierFinder().find(sigAlgId);
    AsymmetricKeyParameter privateKeyAsymKeyParam = PrivateKeyFactory.createKey(pair.getPrivate().getEncoded());
    SubjectPublicKeyInfo subPubKeyInfo = SubjectPublicKeyInfo.getInstance(pair.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());

    X509v1CertificateBuilder v1CertGen = new X509v1CertificateBuilder(name, sn, from, to, name, subPubKeyInfo);
    X509CertificateHolder certificateHolder = v1CertGen.build(sigGen);
    return new JcaX509CertificateConverter().setProvider("BC").getCertificate(certificateHolder);
  } catch (CertificateException ce) {
    throw ce;
  } catch (Exception e) {
    throw new CertificateException(e);
  }
}
 
开发者ID:becketqin,项目名称:likafka-clients,代码行数:37,代码来源:TestSslUtils.java

示例6: generateCertificate

import org.bouncycastle.crypto.params.AsymmetricKeyParameter; //导入依赖的package包/类
/**
 * Create a self-signed X.509 Certificate.
 * From http://bfo.com/blog/2011/03/08/odds_and_ends_creating_a_new_x_509_certificate.html.
 *
 * @param dn the X.509 Distinguished Name, eg "CN=Test, L=London, C=GB"
 * @param pair the KeyPair
 * @param days how many days from now the Certificate is valid for
 * @param algorithm the signing algorithm, eg "SHA1withRSA"
 * @return the self-signed certificate
 * @throws CertificateException thrown if a security error or an IO error occurred.
 */
public static X509Certificate generateCertificate(String dn, KeyPair pair,
                                                  int days, String algorithm)
    throws  CertificateException {

    try {
        Security.addProvider(new BouncyCastleProvider());
        AlgorithmIdentifier sigAlgId = new DefaultSignatureAlgorithmIdentifierFinder().find(algorithm);
        AlgorithmIdentifier digAlgId = new DefaultDigestAlgorithmIdentifierFinder().find(sigAlgId);
        AsymmetricKeyParameter privateKeyAsymKeyParam = PrivateKeyFactory.createKey(pair.getPrivate().getEncoded());
        SubjectPublicKeyInfo subPubKeyInfo = SubjectPublicKeyInfo.getInstance(pair.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());

        X509v1CertificateBuilder v1CertGen = new X509v1CertificateBuilder(name, sn, from, to, name, subPubKeyInfo);
        X509CertificateHolder certificateHolder = v1CertGen.build(sigGen);
        return new JcaX509CertificateConverter().setProvider("BC").getCertificate(certificateHolder);
    } catch (CertificateException ce) {
        throw ce;
    } catch (Exception e) {
        throw new CertificateException(e);
    }
}
 
开发者ID:txazo,项目名称:kafka,代码行数:37,代码来源:TestSslUtils.java

示例7: verifyRawSignature

import org.bouncycastle.crypto.params.AsymmetricKeyParameter; //导入依赖的package包/类
public boolean verifyRawSignature(SignatureAndHashAlgorithm algorithm, byte[] sigBytes,
    AsymmetricKeyParameter publicKey, byte[] hash)
    throws CryptoException
{
    Signer signer = makeSigner(algorithm, true, false, publicKey);
    if (algorithm == null)
    {
        // Note: Only use the SHA1 part of the (MD5/SHA1) hash
        signer.update(hash, 16, 20);
    }
    else
    {
        signer.update(hash, 0, hash.length);
    }
    return signer.verifySignature(sigBytes);
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:17,代码来源:TlsDSASigner.java

示例8: makeV1Certificate

import org.bouncycastle.crypto.params.AsymmetricKeyParameter; //导入依赖的package包/类
public static X509CertificateHolder makeV1Certificate(AsymmetricCipherKeyPair subKP, String _subDN, AsymmetricCipherKeyPair issKP, String _issDN)
    throws IOException, OperatorCreationException
{
    RSAKeyParameters lwPubKey = (RSAKeyParameters)subKP.getPublic();

    X509v1CertificateBuilder v1CertGen = new X509v1CertificateBuilder(
        new X500Name(_issDN),
        allocateSerialNumber(),
        new Date(System.currentTimeMillis()),
        new Date(System.currentTimeMillis() + (1000L * 60 * 60 * 24 * 100)),
        new X500Name(_subDN),
        new SubjectPublicKeyInfo(new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, DERNull.INSTANCE), new RSAPublicKey(lwPubKey.getModulus(), lwPubKey.getExponent()))
    );

    AlgorithmIdentifier sigAlgId = new DefaultSignatureAlgorithmIdentifierFinder().find("SHA1WithRSAEncryption");
    AlgorithmIdentifier digAlgId = new DefaultDigestAlgorithmIdentifierFinder().find(sigAlgId);

    ContentSigner sigGen = new BcRSAContentSignerBuilder(sigAlgId, digAlgId).build((AsymmetricKeyParameter)issKP.getPrivate());


    return v1CertGen.build(sigGen);
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:23,代码来源:CMSTestUtil.java

示例9: createServerTransport

import org.bouncycastle.crypto.params.AsymmetricKeyParameter; //导入依赖的package包/类
static DTLSTransport createServerTransport(final RTCCertificate rtcCertificate,
                                           final DatagramTransport transport) throws IOException {

    final DefaultTlsServer defaultTlsServer = new DefaultTlsServer() {

        private final AsymmetricKeyParameter privateKeyAsymKeyParam = PrivateKeyFactory.createKey(rtcCertificate.getKeyPair()
                                                                                                                .getPrivate()
                                                                                                                .getEncoded());
        private final Certificate cCert = new Certificate(new org.bouncycastle.asn1.x509.Certificate[]{rtcCertificate.getCertificate().toASN1Structure()});

        @Override
        protected ProtocolVersion getMaximumVersion() {
            return ProtocolVersion.DTLSv10;
        }

        @Override
        protected ProtocolVersion getMinimumVersion() {
            return ProtocolVersion.DTLSv10;
        }

        @Override
        protected TlsSignerCredentials getRSASignerCredentials() throws IOException {
            return new DefaultTlsSignerCredentials(this.context,
                                                   this.cCert,
                                                   this.privateKeyAsymKeyParam);
        }
    };

    return new DTLSServerProtocol(SECURE_RANDOM).accept(defaultTlsServer,
                                                        transport);
}
 
开发者ID:Zubnix,项目名称:rtcdcjava,代码行数:32,代码来源:DTLSTransportFactory.java

示例10: createSignatureStream

import org.bouncycastle.crypto.params.AsymmetricKeyParameter; //导入依赖的package包/类
private BcSignerOutputStream createSignatureStream(AlgorithmIdentifier algorithm, AsymmetricKeyParameter publicKey)
    throws OperatorCreationException
{
    Signer sig = createSigner(algorithm);

    sig.init(false, publicKey);

    return new BcSignerOutputStream(sig);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:10,代码来源:BcContentVerifierProviderBuilder.java

示例11: generatePublicKeyParameter

import org.bouncycastle.crypto.params.AsymmetricKeyParameter; //导入依赖的package包/类
static public AsymmetricKeyParameter generatePublicKeyParameter(
    PublicKey    key)
    throws InvalidKeyException
{
    if (key instanceof DHPublicKey)
    {
        DHPublicKey    k = (DHPublicKey)key;

        return new DHPublicKeyParameters(k.getY(),
            new DHParameters(k.getParams().getP(), k.getParams().getG(), null, k.getParams().getL()));
    }

    throw new InvalidKeyException("can't identify DH public key.");
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:15,代码来源:DHUtil.java

示例12: generatePrivateKeyParameter

import org.bouncycastle.crypto.params.AsymmetricKeyParameter; //导入依赖的package包/类
static public AsymmetricKeyParameter generatePrivateKeyParameter(
    PrivateKey    key)
    throws InvalidKeyException
{
    if (key instanceof DHPrivateKey)
    {
        DHPrivateKey    k = (DHPrivateKey)key;

        return new DHPrivateKeyParameters(k.getX(),
            new DHParameters(k.getParams().getP(), k.getParams().getG(), null, k.getParams().getL()));
    }
                    
    throw new InvalidKeyException("can't identify DH private key.");
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:15,代码来源:DHUtil.java

示例13: generatePublicKeyParameter

import org.bouncycastle.crypto.params.AsymmetricKeyParameter; //导入依赖的package包/类
static public AsymmetricKeyParameter generatePublicKeyParameter(
    PublicKey key)
    throws InvalidKeyException
{
    if (key instanceof BCRainbowPublicKey)
    {
        BCRainbowPublicKey k = (BCRainbowPublicKey)key;

        return new RainbowPublicKeyParameters(k.getDocLength(), k.getCoeffQuadratic(),
            k.getCoeffSingular(), k.getCoeffScalar());
    }

    throw new InvalidKeyException("can't identify Rainbow public key: " + key.getClass().getName());
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:15,代码来源:RainbowKeysToParams.java

示例14: generatePrivateKeyParameter

import org.bouncycastle.crypto.params.AsymmetricKeyParameter; //导入依赖的package包/类
static public AsymmetricKeyParameter generatePrivateKeyParameter(
    PrivateKey key)
    throws InvalidKeyException
{
    if (key instanceof BCRainbowPrivateKey)
    {
        BCRainbowPrivateKey k = (BCRainbowPrivateKey)key;
        return new RainbowPrivateKeyParameters(k.getInvA1(), k.getB1(),
            k.getInvA2(), k.getB2(), k.getVi(), k.getLayers());
    }

    throw new InvalidKeyException("can't identify Rainbow private key.");
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:14,代码来源:RainbowKeysToParams.java

示例15: generatePrivateKeyParameter

import org.bouncycastle.crypto.params.AsymmetricKeyParameter; //导入依赖的package包/类
static public AsymmetricKeyParameter generatePrivateKeyParameter(
    PrivateKey key)
    throws InvalidKeyException
{
    if (key instanceof BCMcElieceCCA2PrivateKey)
    {
        BCMcElieceCCA2PrivateKey k = (BCMcElieceCCA2PrivateKey)key;
        return new McElieceCCA2PrivateKeyParameters(k.getOIDString(), k.getN(), k.getK(), k.getField(), k.getGoppaPoly(),
            k.getP(), k.getH(), k.getQInv(), k.getMcElieceCCA2Parameters());
    }

    throw new InvalidKeyException("can't identify McElieceCCA2 private key.");
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:14,代码来源:McElieceCCA2KeysToParams.java


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