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


Java AsymmetricCipherKeyPair.getPublic方法代码示例

本文整理汇总了Java中org.bouncycastle.crypto.AsymmetricCipherKeyPair.getPublic方法的典型用法代码示例。如果您正苦于以下问题:Java AsymmetricCipherKeyPair.getPublic方法的具体用法?Java AsymmetricCipherKeyPair.getPublic怎么用?Java AsymmetricCipherKeyPair.getPublic使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bouncycastle.crypto.AsymmetricCipherKeyPair的用法示例。


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

示例1: generateKeyPair

import org.bouncycastle.crypto.AsymmetricCipherKeyPair; //导入方法依赖的package包/类
public KeyPair generateKeyPair()
{
    if (!initialised)
    {
        param = new RainbowKeyGenerationParameters(random, new RainbowParameters(new RainbowParameterSpec().getVi()));

        engine.init(param);
        initialised = true;
    }

    AsymmetricCipherKeyPair pair = engine.generateKeyPair();
    RainbowPublicKeyParameters pub = (RainbowPublicKeyParameters)pair.getPublic();
    RainbowPrivateKeyParameters priv = (RainbowPrivateKeyParameters)pair.getPrivate();

    return new KeyPair(new BCRainbowPublicKey(pub),
        new BCRainbowPrivateKey(priv));
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:18,代码来源:RainbowKeyPairGeneratorSpi.java

示例2: generateKeyPair

import org.bouncycastle.crypto.AsymmetricCipherKeyPair; //导入方法依赖的package包/类
public KeyPair generateKeyPair()
{
    if (!initialised)
    {
        DSAParametersGenerator pGen = new DSAParametersGenerator();

        pGen.init(strength, certainty, random);
        param = new DSAKeyGenerationParameters(random, pGen.generateParameters());
        engine.init(param);
        initialised = true;
    }

    AsymmetricCipherKeyPair pair = engine.generateKeyPair();
    DSAPublicKeyParameters pub = (DSAPublicKeyParameters)pair.getPublic();
    DSAPrivateKeyParameters priv = (DSAPrivateKeyParameters)pair.getPrivate();

    return new KeyPair(new BCDSAPublicKey(pub),
        new BCDSAPrivateKey(priv));
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:20,代码来源:KeyPairGeneratorSpi.java

示例3: makeCertificate

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

    X509v3CertificateBuilder v3CertGen = new X509v3CertificateBuilder(
        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());

    v3CertGen.addExtension(
        X509Extension.basicConstraints,
        false,
        new BasicConstraints(_ca));

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

示例4: generateKeyPair

import org.bouncycastle.crypto.AsymmetricCipherKeyPair; //导入方法依赖的package包/类
public KeyPair generateKeyPair()
{
    if (!initialised)
    {
        init(new GOST3410ParameterSpec(CryptoProObjectIdentifiers.gostR3410_94_CryptoPro_A.getId()), new SecureRandom());
    }

    AsymmetricCipherKeyPair pair = engine.generateKeyPair();
    GOST3410PublicKeyParameters pub = (GOST3410PublicKeyParameters)pair.getPublic();
    GOST3410PrivateKeyParameters priv = (GOST3410PrivateKeyParameters)pair.getPrivate();

    return new KeyPair(new BCGOST3410PublicKey(pub, gost3410Params), new BCGOST3410PrivateKey(priv, gost3410Params));
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:14,代码来源:KeyPairGeneratorSpi.java

示例5: generateKeyPair

import org.bouncycastle.crypto.AsymmetricCipherKeyPair; //导入方法依赖的package包/类
public KeyPair generateKeyPair()
{
    AsymmetricCipherKeyPair pair = engine.generateKeyPair();
    RSAKeyParameters pub = (RSAKeyParameters)pair.getPublic();
    RSAPrivateCrtKeyParameters priv = (RSAPrivateCrtKeyParameters)pair.getPrivate();

    return new KeyPair(new BCRSAPublicKey(pub),
        new BCRSAPrivateCrtKey(priv));
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:10,代码来源:KeyPairGeneratorSpi.java

示例6: initEnc

import org.bouncycastle.crypto.AsymmetricCipherKeyPair; //导入方法依赖的package包/类
public ECPoint initEnc(SM2 sm2, ECPoint userKey) {
    AsymmetricCipherKeyPair key = sm2.ecc_key_pair_generator.generateKeyPair();
    ECPrivateKeyParameters ecpriv = (ECPrivateKeyParameters) key.getPrivate();
    ECPublicKeyParameters ecpub = (ECPublicKeyParameters) key.getPublic();
    BigInteger k = ecpriv.getD();
    ECPoint c1 = ecpub.getQ();
    this.p2 = userKey.multiply(k);
    reset();
    return c1;
}
 
开发者ID:nuls-io,项目名称:nuls,代码行数:11,代码来源:Cipher.java

示例7: createNew

import org.bouncycastle.crypto.AsymmetricCipherKeyPair; //导入方法依赖的package包/类
/**
 * Create a new PrivateKey using the platform provided secure random source.
 *
 * @param compressed set to false if you relly want legacy format
 * @return new PrivateKey
 */
public static PrivateKey createNew(boolean compressed) {
    ECKeyPairGenerator generator = new ECKeyPairGenerator();
    ECKeyGenerationParameters keygenParams = new ECKeyGenerationParameters(domain, secureRandom);
    generator.init(keygenParams);
    AsymmetricCipherKeyPair keypair = generator.generateKeyPair();
    ECPrivateKeyParameters privParams = (ECPrivateKeyParameters) keypair.getPrivate();
    ECPublicKeyParameters pubParams = (ECPublicKeyParameters) keypair.getPublic();
    return new PrivateKey(privParams.getD(), compressed, pubParams.getQ().getEncoded(compressed));
}
 
开发者ID:DigitalAssetCom,项目名称:-deprecated-hlp-candidate,代码行数:16,代码来源:PrivateKey.java

示例8: setUpClass

import org.bouncycastle.crypto.AsymmetricCipherKeyPair; //导入方法依赖的package包/类
@BeforeClass
public static void setUpClass() throws CoseException {

    X9ECParameters p = NISTNamedCurves.getByName("P-256");
    
    ECDomainParameters parameters = new ECDomainParameters(p.getCurve(), p.getG(), p.getN(), p.getH());
    ECKeyPairGenerator pGen = new ECKeyPairGenerator();
    ECKeyGenerationParameters genParam = new ECKeyGenerationParameters(parameters, null);
    pGen.init(genParam);
    
    AsymmetricCipherKeyPair p1 = pGen.generateKeyPair();
    
    keyPublic = (ECPublicKeyParameters) p1.getPublic();
    keyPrivate = (ECPrivateKeyParameters) p1.getPrivate();
    
byte[] rgbX = keyPublic.getQ().normalize().getXCoord().getEncoded();
byte[] rgbY = keyPublic.getQ().normalize().getYCoord().getEncoded();
boolean signY = true;
byte[] rgbD = keyPrivate.getD().toByteArray();

CBORObject key = CBORObject.NewMap();
    key.Add(KeyKeys.KeyType.AsCBOR(), KeyKeys.KeyType_EC2);
    key.Add(KeyKeys.EC2_Curve.AsCBOR(), KeyKeys.EC2_P256);
    key.Add(KeyKeys.EC2_X.AsCBOR(), rgbX);
    key.Add(KeyKeys.EC2_Y.AsCBOR(), rgbY);
    cnKeyPublic = new OneKey(key);
    
    key = CBORObject.NewMap();
    key.Add(KeyKeys.KeyType.AsCBOR(), KeyKeys.KeyType_EC2);
    key.Add(KeyKeys.EC2_Curve.AsCBOR(), KeyKeys.EC2_P256);
    key.Add(KeyKeys.EC2_X.AsCBOR(), rgbX);
    key.Add(KeyKeys.EC2_Y.AsCBOR(), rgbY);
    cnKeyPublicCompressed = new OneKey(key);

    key = CBORObject.NewMap();
    key.Add(KeyKeys.KeyType.AsCBOR(), KeyKeys.KeyType_EC2);
    key.Add(KeyKeys.EC2_Curve.AsCBOR(), KeyKeys.EC2_P256);
    key.Add(KeyKeys.EC2_D.AsCBOR(), rgbD);
    cnKeyPrivate = new OneKey(key);
}
 
开发者ID:cose-wg,项目名称:COSE-JAVA,代码行数:41,代码来源:Sign1MessageTest.java

示例9: setEcDhParams

import org.bouncycastle.crypto.AsymmetricCipherKeyPair; //导入方法依赖的package包/类
protected void setEcDhParams() {
    msg.prepareComputations();
    generateNamedCurveList(msg);
    generatePointFormatList(msg);
    prepareCurveType(msg);
    prepareNamedCurve(msg);

    ECDomainParameters ecParams = generateEcParameters(msg);
    AsymmetricCipherKeyPair keyPair = TlsECCUtils.generateECKeyPair(chooser.getContext().getBadSecureRandom(),
            ecParams);

    pubEcParams = (ECPublicKeyParameters) keyPair.getPublic();
    privEcParams = (ECPrivateKeyParameters) keyPair.getPrivate();
}
 
开发者ID:RUB-NDS,项目名称:TLS-Attacker,代码行数:15,代码来源:ECDHEServerKeyExchangePreparator.java

示例10: generateEphemeralServerKeyExchange

import org.bouncycastle.crypto.AsymmetricCipherKeyPair; //导入方法依赖的package包/类
public static DHPrivateKeyParameters generateEphemeralServerKeyExchange(SecureRandom random, DHParameters dhParams,
    OutputStream output) throws IOException
{
    AsymmetricCipherKeyPair kp = generateDHKeyPair(random, dhParams);

    DHPublicKeyParameters dhPublic = (DHPublicKeyParameters)kp.getPublic();
    new ServerDHParams(dhPublic).encode(output);

    return (DHPrivateKeyParameters)kp.getPrivate();
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:11,代码来源:TlsDHUtils.java

示例11: generateEphemeralClientKeyExchange

import org.bouncycastle.crypto.AsymmetricCipherKeyPair; //导入方法依赖的package包/类
public static ECPrivateKeyParameters generateEphemeralClientKeyExchange(SecureRandom random, short[] ecPointFormats,
    ECDomainParameters ecParams, OutputStream output) throws IOException
{
    AsymmetricCipherKeyPair kp = generateECKeyPair(random, ecParams);

    ECPublicKeyParameters ecPublicKey = (ECPublicKeyParameters) kp.getPublic();
    writeECPoint(ecPointFormats, ecPublicKey.getQ(), output);

    return (ECPrivateKeyParameters) kp.getPrivate();
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:11,代码来源:TlsECCUtils.java

示例12: testGPWithRandom

import org.bouncycastle.crypto.AsymmetricCipherKeyPair; //导入方法依赖的package包/类
private void testGPWithRandom(
    DHKeyPairGenerator kpGen)
{
    //
    // generate first pair
    //
    AsymmetricCipherKeyPair     pair = kpGen.generateKeyPair();

    DHPublicKeyParameters       pu1 = (DHPublicKeyParameters)pair.getPublic();
    DHPrivateKeyParameters      pv1 = (DHPrivateKeyParameters)pair.getPrivate();
    //
    // generate second pair
    //
    pair = kpGen.generateKeyPair();

    DHPublicKeyParameters       pu2 = (DHPublicKeyParameters)pair.getPublic();
    DHPrivateKeyParameters      pv2 = (DHPrivateKeyParameters)pair.getPrivate();

    //
    // two way
    //
    DHAgreement    e1 = new DHAgreement();
    DHAgreement    e2 = new DHAgreement();

    e1.init(new ParametersWithRandom(pv1, new SecureRandom()));
    e2.init(new ParametersWithRandom(pv2, new SecureRandom()));

    BigInteger   m1 = e1.calculateMessage();
    BigInteger   m2 = e2.calculateMessage();

    BigInteger   k1 = e1.calculateAgreement(pu2, m2);
    BigInteger   k2 = e2.calculateAgreement(pu1, m1);
    
    if (!k1.equals(k2))
    {
        fail("basic with random 2-way test failed");
    }
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:39,代码来源:DHTest.java

示例13: testSimpleWithRandom

import org.bouncycastle.crypto.AsymmetricCipherKeyPair; //导入方法依赖的package包/类
private void testSimpleWithRandom(
    DHBasicKeyPairGenerator kpGen)
{
    //
    // generate first pair
    //
    AsymmetricCipherKeyPair     pair = kpGen.generateKeyPair();

    DHPublicKeyParameters       pu1 = (DHPublicKeyParameters)pair.getPublic();
    DHPrivateKeyParameters      pv1 = (DHPrivateKeyParameters)pair.getPrivate();
    //
    // generate second pair
    //
    pair = kpGen.generateKeyPair();

    DHPublicKeyParameters       pu2 = (DHPublicKeyParameters)pair.getPublic();
    DHPrivateKeyParameters      pv2 = (DHPrivateKeyParameters)pair.getPrivate();

    //
    // two way
    //
    DHBasicAgreement    e1 = new DHBasicAgreement();
    DHBasicAgreement    e2 = new DHBasicAgreement();

    e1.init(new ParametersWithRandom(pv1, new SecureRandom()));
    e2.init(new ParametersWithRandom(pv2, new SecureRandom()));

    BigInteger   k1 = e1.calculateAgreement(pu2);
    BigInteger   k2 = e2.calculateAgreement(pu1);

    if (!k1.equals(k2))
    {
        fail("basic with random 2-way test failed");
    }
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:36,代码来源:DHTest.java

示例14: generateEphemeralClientKeyExchange

import org.bouncycastle.crypto.AsymmetricCipherKeyPair; //导入方法依赖的package包/类
public static DHPrivateKeyParameters generateEphemeralClientKeyExchange(SecureRandom random, DHParameters dhParams,
    OutputStream output) throws IOException
{
    AsymmetricCipherKeyPair kp = generateDHKeyPair(random, dhParams);

    DHPublicKeyParameters dhPublic = (DHPublicKeyParameters) kp.getPublic();
    writeDHParameter(dhPublic.getY(), output);

    return (DHPrivateKeyParameters) kp.getPrivate();
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:11,代码来源:TlsDHUtils.java

示例15: generateSignature

import org.bouncycastle.crypto.AsymmetricCipherKeyPair; //导入方法依赖的package包/类
/**
 * generate a signature for the given message using the key we were
 * initialised with.  Generally, the order of the curve should be at 
 * least as long as the hash of the message of interest, and with 
 * ECNR it *must* be at least as long.  
 *
 * @param digest  the digest to be signed.
 * @exception DataLengthException if the digest is longer than the key allows
 */
public BigInteger[] generateSignature(
    byte[] digest)
{
    if (! this.forSigning) 
    {
        throw new IllegalStateException("not initialised for signing");
    }
    
    BigInteger n = ((ECPrivateKeyParameters)this.key).getParameters().getN();
    int nBitLength = n.bitLength();
    
    BigInteger e = new BigInteger(1, digest);
    int eBitLength = e.bitLength();
    
    ECPrivateKeyParameters  privKey = (ECPrivateKeyParameters)key;
           
    if (eBitLength > nBitLength) 
    {
        throw new DataLengthException("input too large for ECNR key.");
    }

    BigInteger r = null;
    BigInteger s = null;

    AsymmetricCipherKeyPair tempPair;
    do // generate r
    {
        // generate another, but very temporary, key pair using 
        // the same EC parameters
        ECKeyPairGenerator keyGen = new ECKeyPairGenerator();
        
        keyGen.init(new ECKeyGenerationParameters(privKey.getParameters(), this.random));
        
        tempPair = keyGen.generateKeyPair();

        //    BigInteger Vx = tempPair.getPublic().getW().getAffineX();
        ECPublicKeyParameters V = (ECPublicKeyParameters)tempPair.getPublic();        // get temp's public key
        BigInteger Vx = V.getQ().getX().toBigInteger();        // get the point's x coordinate
        
        r = Vx.add(e).mod(n);
    }
    while (r.equals(ECConstants.ZERO));

    // generate s
    BigInteger x = privKey.getD();                // private key value
    BigInteger u = ((ECPrivateKeyParameters)tempPair.getPrivate()).getD();    // temp's private key value
    s = u.subtract(r.multiply(x)).mod(n);

    BigInteger[]  res = new BigInteger[2];
    res[0] = r;
    res[1] = s;

    return res;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:64,代码来源:ECNRSigner.java


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