Java 类org.bouncycastle.crypto.AsymmetricCipherKeyPair 实例源码

项目:ipack    文件:RainbowKeyPairGeneratorSpi.java   
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));
}
项目:ipack    文件:NTRUSigningKeyPairGenerator.java   
/**
 * Generates a new signature key pair. Runs in a single thread.
 *
 * @return a key pair
 */
public AsymmetricCipherKeyPair generateKeyPairSingleThread()
{
    List<NTRUSigningPrivateKeyParameters.Basis> basises = new ArrayList<NTRUSigningPrivateKeyParameters.Basis>();
    NTRUSigningPublicKeyParameters pub = null;
    for (int k = params.B; k >= 0; k--)
    {
        NTRUSigningPrivateKeyParameters.Basis basis = generateBoundedBasis();
        basises.add(basis);
        if (k == 0)
        {
            pub = new NTRUSigningPublicKeyParameters(basis.h, params.getSigningParameters());
        }
    }
    NTRUSigningPrivateKeyParameters priv = new NTRUSigningPrivateKeyParameters(basises, pub);
    return new AsymmetricCipherKeyPair(pub, priv);
}
项目:ipack    文件:RainbowKeyPairGenerator.java   
/**
 * This function generates a Rainbow key pair.
 *
 * @return the generated key pair
 */
public AsymmetricCipherKeyPair genKeyPair()
{
    RainbowPrivateKeyParameters privKey;
    RainbowPublicKeyParameters pubKey;

    if (!initialized)
    {
        initializeDefault();
    }

    /* choose all coefficients at random */
    keygen();

    /* now marshall them to PrivateKey */
    privKey = new RainbowPrivateKeyParameters(A1inv, b1, A2inv, b2, vi, layers);


    /* marshall to PublicKey */
    pubKey = new RainbowPublicKeyParameters(vi[vi.length - 1] - vi[0], pub_quadratic, pub_singular, pub_scalar);

    return new AsymmetricCipherKeyPair(pubKey, privKey);
}
项目:ipack    文件:TlsECDHKeyExchange.java   
public void generateClientKeyExchange(OutputStream output)
    throws IOException
{
    if (agreementCredentials != null)
    {
        return;
    }

    AsymmetricCipherKeyPair ecAgreeClientKeyPair = TlsECCUtils.generateECKeyPair(context.getSecureRandom(),
        ecAgreeServerPublicKey.getParameters());
    this.ecAgreeClientPrivateKey = (ECPrivateKeyParameters)ecAgreeClientKeyPair.getPrivate();

    byte[] point = TlsECCUtils.serializeECPublicKey(serverECPointFormats,
        (ECPublicKeyParameters)ecAgreeClientKeyPair.getPublic());

    TlsUtils.writeOpaque8(point, output);
}
项目:ipack    文件:KeyPairGeneratorSpi.java   
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));
}
项目:Direct-File-Downloader    文件:DSAKeyPairGenerator.java   
public AsymmetricCipherKeyPair generateKeyPair()
{
    BigInteger      p, q, g, x, y;
    DSAParameters   dsaParams = param.getParameters();
    SecureRandom    random = param.getRandom();

    q = dsaParams.getQ();
    p = dsaParams.getP();
    g = dsaParams.getG();

    do
    {
        x = new BigInteger(160, random);
    }
    while (x.equals(ZERO)  || x.compareTo(q) >= 0);

    //
    // calculate the public key.
    //
    y = g.modPow(x, p);

    return new AsymmetricCipherKeyPair(
            new DSAPublicKeyParameters(y, dsaParams),
            new DSAPrivateKeyParameters(x, dsaParams));
}
项目:Direct-File-Downloader    文件:DHKeyPairGenerator.java   
public AsymmetricCipherKeyPair generateKeyPair()
  {
      BigInteger      p, g, x, y;
      int             qLength = param.getStrength() - 1;
      DHParameters    dhParams = param.getParameters();

      p = dhParams.getP();
      g = dhParams.getG();

      //
      // calculate the private key
      //
x = new BigInteger(qLength, param.getRandom());

      //
      // calculate the public key.
      //
      y = g.modPow(x, p);

      return new AsymmetricCipherKeyPair(
              new DHPublicKeyParameters(y, dhParams),
              new DHPrivateKeyParameters(x, dhParams));
  }
项目:Direct-File-Downloader    文件:ECKeyPairGenerator.java   
/**
    * Given the domain parameters this routine generates an EC key
    * pair in accordance with X9.62 section 5.2.1 pages 26, 27.
    */
   public AsymmetricCipherKeyPair generateKeyPair()
   {
    BigInteger n = params.getN();
    int           nBitLength = n.bitLength();
    BigInteger d;

    do
    {
        d = new BigInteger(nBitLength, random);
    }
    while (d.equals(ZERO)  || (d.compareTo(n) >= 0));

    ECPoint Q = params.getG().multiply(d);

    return new AsymmetricCipherKeyPair(
           new ECPublicKeyParameters(Q, params),
        new ECPrivateKeyParameters(d, params));
}
项目:Direct-File-Downloader    文件:DHBasicKeyPairGenerator.java   
public AsymmetricCipherKeyPair generateKeyPair()
  {
      BigInteger      p, g, x, y;
      int             qLength = param.getStrength() - 1;
      DHParameters    dhParams = param.getParameters();

      p = dhParams.getP();
      g = dhParams.getG();

      //
      // calculate the private key
      //
x = new BigInteger(qLength, param.getRandom());

      //
      // calculate the public key.
      //
      y = g.modPow(x, p);

      return new AsymmetricCipherKeyPair(
              new DHPublicKeyParameters(y, dhParams),
              new DHPrivateKeyParameters(x, dhParams));
  }
项目:gwt-crypto    文件:RainbowKeyPairGenerator.java   
/**
 * This function generates a Rainbow key pair.
 *
 * @return the generated key pair
 */
public AsymmetricCipherKeyPair genKeyPair()
{
    RainbowPrivateKeyParameters privKey;
    RainbowPublicKeyParameters pubKey;

    if (!initialized)
    {
        initializeDefault();
    }

    /* choose all coefficients at random */
    keygen();

    /* now marshall them to PrivateKey */
    privKey = new RainbowPrivateKeyParameters(A1inv, b1, A2inv, b2, vi, layers);


    /* marshall to PublicKey */
    pubKey = new RainbowPublicKeyParameters(vi[vi.length - 1] - vi[0], pub_quadratic, pub_singular, pub_scalar);

    return new AsymmetricCipherKeyPair(pubKey, privKey);
}
项目:gwt-crypto    文件:CMSTestUtil.java   
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);
}
项目:gwt-crypto    文件:CMSTestUtil.java   
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);
}
项目:SSI_Bitcoin-Storage    文件:Address.java   
/*************
 * This method will create the ECDSA public and private key which is returned in a Byte array of Byte arrays, index 0 is the private key and
 * index 1 of the array will return the ECDSA public key
 * 
 * -Wisdom: This guy didn't check whether the returned Private Key would be more than 32.
 * @return

 */
private byte[][] ECDSAgeneratePublicAndPrivateKey(){
       int length = 0;
       byte[][] keys;

    do{

    ECKeyPairGenerator gen = new ECKeyPairGenerator();
    SecureRandom secureRandom = new SecureRandom();
        X9ECParameters secnamecurves = SECNamedCurves.getByName("secp256k1");
    ECDomainParameters ecParams = new ECDomainParameters(secnamecurves.getCurve(), secnamecurves.getG(), secnamecurves.getN(), secnamecurves.getH());
    ECKeyGenerationParameters keyGenParam = new ECKeyGenerationParameters(ecParams, secureRandom);
    gen.init(keyGenParam);
    AsymmetricCipherKeyPair kp = gen.generateKeyPair();
    ECPrivateKeyParameters privatekey = (ECPrivateKeyParameters)kp.getPrivate();
    ECPoint dd = secnamecurves.getG().multiply(privatekey.getD());
    byte[] publickey=new byte[65];
    System.arraycopy(dd.getY().toBigInteger().toByteArray(), 0, publickey, 64-dd.getY().toBigInteger().toByteArray().length+1, dd.getY().toBigInteger().toByteArray().length);
    System.arraycopy(dd.getX().toBigInteger().toByteArray(), 0, publickey, 32-dd.getX().toBigInteger().toByteArray().length+1, dd.getX().toBigInteger().toByteArray().length);
    publickey[0]=4;
        length = privatekey.getD().toByteArray().length;
        keys = new byte[][]{privatekey.getD().toByteArray(),publickey};

    }while(length != 32);
    return keys;
}
项目:Aki-SSL    文件:NTRUSigningKeyPairGenerator.java   
/**
 * Generates a new signature key pair. Runs in a single thread.
 *
 * @return a key pair
 */
public AsymmetricCipherKeyPair generateKeyPairSingleThread()
{
    List<NTRUSigningPrivateKeyParameters.Basis> basises = new ArrayList<NTRUSigningPrivateKeyParameters.Basis>();
    NTRUSigningPublicKeyParameters pub = null;
    for (int k = params.B; k >= 0; k--)
    {
        NTRUSigningPrivateKeyParameters.Basis basis = generateBoundedBasis();
        basises.add(basis);
        if (k == 0)
        {
            pub = new NTRUSigningPublicKeyParameters(basis.h, params.getSigningParameters());
        }
    }
    NTRUSigningPrivateKeyParameters priv = new NTRUSigningPrivateKeyParameters(basises, pub);
    return new AsymmetricCipherKeyPair(pub, priv);
}
项目:Aki-SSL    文件:RainbowKeyPairGenerator.java   
/**
 * This function generates a Rainbow key pair.
 *
 * @return the generated key pair
 */
public AsymmetricCipherKeyPair genKeyPair()
{
    RainbowPrivateKeyParameters privKey;
    RainbowPublicKeyParameters pubKey;

    if (!initialized)
    {
        initializeDefault();
    }

    /* choose all coefficients at random */
    keygen();

    /* now marshall them to PrivateKey */
    privKey = new RainbowPrivateKeyParameters(A1inv, b1, A2inv, b2, vi, layers);


    /* marshall to PublicKey */
    pubKey = new RainbowPublicKeyParameters(vi[vi.length - 1] - vi[0], pub_quadratic, pub_singular, pub_scalar);

    return new AsymmetricCipherKeyPair(pubKey, privKey);
}
项目:Aki-SSL    文件:RainbowKeyPairGeneratorSpi.java   
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));
}
项目:Aki-SSL    文件:KeyPairGeneratorSpi.java   
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));
}
项目:ipack    文件:NTRUSigningKeyPairGenerator.java   
/**
 * Generates a new signature key pair. Starts <code>B+1</code> threads.
 *
 * @return a key pair
 */
public AsymmetricCipherKeyPair generateKeyPair()
{
    NTRUSigningPublicKeyParameters pub = null;
    ExecutorService executor = Executors.newCachedThreadPool();
    List<Future<NTRUSigningPrivateKeyParameters.Basis>> bases = new ArrayList<Future<NTRUSigningPrivateKeyParameters.Basis>>();
    for (int k = params.B; k >= 0; k--)
    {
        bases.add(executor.submit(new BasisGenerationTask()));
    }
    executor.shutdown();

    List<NTRUSigningPrivateKeyParameters.Basis> basises = new ArrayList<NTRUSigningPrivateKeyParameters.Basis>();

    for (int k = params.B; k >= 0; k--)
    {
        Future<NTRUSigningPrivateKeyParameters.Basis> basis = bases.get(k);
        try
        {
            basises.add(basis.get());
            if (k == params.B)
            {
                pub = new NTRUSigningPublicKeyParameters(basis.get().h, params.getSigningParameters());
            }
        }
        catch (Exception e)
        {
            throw new IllegalStateException(e);
        }
    }
    NTRUSigningPrivateKeyParameters priv = new NTRUSigningPrivateKeyParameters(basises, pub);
    AsymmetricCipherKeyPair kp = new AsymmetricCipherKeyPair(pub, priv);
    return kp;
}
项目:ipack    文件:TlsDHEKeyExchange.java   
public byte[] generateServerKeyExchange()
    throws IOException
{

    if (this.dhParameters == null)
    {
        throw new TlsFatalAlert(AlertDescription.internal_error);
    }

    ByteArrayOutputStream buf = new ByteArrayOutputStream();

    DHKeyPairGenerator kpg = new DHKeyPairGenerator();
    kpg.init(new DHKeyGenerationParameters(context.getSecureRandom(), this.dhParameters));
    AsymmetricCipherKeyPair kp = kpg.generateKeyPair();

    BigInteger Ys = ((DHPublicKeyParameters)kp.getPublic()).getY();

    TlsDHUtils.writeDHParameter(dhParameters.getP(), buf);
    TlsDHUtils.writeDHParameter(dhParameters.getG(), buf);
    TlsDHUtils.writeDHParameter(Ys, buf);

    byte[] digestInput = buf.toByteArray();

    Digest d = new CombinedHash();
    SecurityParameters securityParameters = context.getSecurityParameters();
    d.update(securityParameters.clientRandom, 0, securityParameters.clientRandom.length);
    d.update(securityParameters.serverRandom, 0, securityParameters.serverRandom.length);
    d.update(digestInput, 0, digestInput.length);

    byte[] hash = new byte[d.getDigestSize()];
    d.doFinal(hash, 0);

    byte[] sigBytes = serverCredentials.generateCertificateSignature(hash);
    /*
     * TODO RFC 5246 4.7. digitally-signed element needs SignatureAndHashAlgorithm prepended from TLS 1.2
     */
    TlsUtils.writeOpaque16(sigBytes, buf);

    return buf.toByteArray();
}
项目:ipack    文件:TlsDHUtils.java   
public static AsymmetricCipherKeyPair generateDHKeyPair(SecureRandom random,
                                                        DHParameters dhParams)
{
    DHBasicKeyPairGenerator dhGen = new DHBasicKeyPairGenerator();
    dhGen.init(new DHKeyGenerationParameters(random, dhParams));
    return dhGen.generateKeyPair();
}
项目:ipack    文件:TlsDHUtils.java   
public static DHPrivateKeyParameters generateEphemeralClientKeyExchange(SecureRandom random,
                                                                        DHParameters dhParams, OutputStream output)
    throws IOException
{

    AsymmetricCipherKeyPair dhAgreeClientKeyPair = generateDHKeyPair(random, dhParams);
    DHPrivateKeyParameters dhAgreeClientPrivateKey = (DHPrivateKeyParameters)dhAgreeClientKeyPair
        .getPrivate();

    BigInteger Yc = ((DHPublicKeyParameters)dhAgreeClientKeyPair.getPublic()).getY();
    byte[] keData = BigIntegers.asUnsignedByteArray(Yc);
    TlsUtils.writeOpaque16(keData, output);

    return dhAgreeClientPrivateKey;
}
项目:ipack    文件:TlsECCUtils.java   
public static AsymmetricCipherKeyPair generateECKeyPair(SecureRandom random, ECDomainParameters ecParams)
{

    ECKeyPairGenerator keyPairGenerator = new ECKeyPairGenerator();
    ECKeyGenerationParameters keyGenerationParameters = new ECKeyGenerationParameters(ecParams, random);
    keyPairGenerator.init(keyGenerationParameters);
    return keyPairGenerator.generateKeyPair();
}
项目:ipack    文件:DHAgreement.java   
/**
 * calculate our initial message.
 */
public BigInteger calculateMessage()
{
    DHKeyPairGenerator dhGen = new DHKeyPairGenerator();
    dhGen.init(new DHKeyGenerationParameters(random, dhParams));
    AsymmetricCipherKeyPair dhPair = dhGen.generateKeyPair();

    this.privateValue = ((DHPrivateKeyParameters)dhPair.getPrivate()).getX();

    return ((DHPublicKeyParameters)dhPair.getPublic()).getY();
}
项目:ipack    文件:ElGamalKeyPairGenerator.java   
public AsymmetricCipherKeyPair generateKeyPair()
{
    DHKeyGeneratorHelper helper = DHKeyGeneratorHelper.INSTANCE;
    ElGamalParameters egp = param.getParameters();
    DHParameters dhp = new DHParameters(egp.getP(), egp.getG(), null, egp.getL());  

    BigInteger x = helper.calculatePrivate(dhp, param.getRandom()); 
    BigInteger y = helper.calculatePublic(dhp, x);

    return new AsymmetricCipherKeyPair(
        new ElGamalPublicKeyParameters(y, egp),
        new ElGamalPrivateKeyParameters(x, egp));
}
项目:ipack    文件:DSAKeyPairGenerator.java   
public AsymmetricCipherKeyPair generateKeyPair()
{
    DSAParameters dsaParams = param.getParameters();

    BigInteger x = generatePrivateKey(dsaParams.getQ(), param.getRandom());
    BigInteger y = calculatePublicKey(dsaParams.getP(), dsaParams.getG(), x);

    return new AsymmetricCipherKeyPair(
        new DSAPublicKeyParameters(y, dsaParams),
        new DSAPrivateKeyParameters(x, dsaParams));
}
项目:ipack    文件:DHKeyPairGenerator.java   
public AsymmetricCipherKeyPair generateKeyPair()
{
    DHKeyGeneratorHelper helper = DHKeyGeneratorHelper.INSTANCE;
    DHParameters dhp = param.getParameters();

    BigInteger x = helper.calculatePrivate(dhp, param.getRandom()); 
    BigInteger y = helper.calculatePublic(dhp, x);

    return new AsymmetricCipherKeyPair(
        new DHPublicKeyParameters(y, dhp),
        new DHPrivateKeyParameters(x, dhp));
}
项目:ipack    文件:DHBasicKeyPairGenerator.java   
public AsymmetricCipherKeyPair generateKeyPair()
{
    DHKeyGeneratorHelper helper = DHKeyGeneratorHelper.INSTANCE;
    DHParameters dhp = param.getParameters();

    BigInteger x = helper.calculatePrivate(dhp, param.getRandom()); 
    BigInteger y = helper.calculatePublic(dhp, x);

    return new AsymmetricCipherKeyPair(
        new DHPublicKeyParameters(y, dhp),
        new DHPrivateKeyParameters(x, dhp));
}
项目:ipack    文件:EphemeralKeyPairGenerator.java   
public EphemeralKeyPair generate()
{
    AsymmetricCipherKeyPair eph = gen.generateKeyPair();

    // Encode the ephemeral public key
     return new EphemeralKeyPair(eph, keyEncoder);
}
项目:ipack    文件:KeyPairGeneratorSpi.java   
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));
}
项目:ipack    文件:KeyPairGeneratorSpi.java   
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));
}
项目:nuls    文件:Cipher.java   
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;
}
项目:-deprecated-hlp-candidate    文件:PrivateKey.java   
/**
 * 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));
}
项目:Direct-File-Downloader    文件:JDKKeyPairGenerator.java   
public KeyPair generateKeyPair()
{
    if (!initialised)
    {
        throw new IllegalStateException("EC Key Pair Generator not initialised");
    }

    AsymmetricCipherKeyPair     pair = engine.generateKeyPair();
    ECPublicKeyParameters       pub = (ECPublicKeyParameters)pair.getPublic();
    ECPrivateKeyParameters      priv = (ECPrivateKeyParameters)pair.getPrivate();

    return new KeyPair(new JCEECPublicKey(algorithm, pub, ecParams),
                       new JCEECPrivateKey(algorithm, priv, ecParams));
}
项目:COSE-JAVA    文件:Sign1MessageTest.java   
@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);
}
项目:TLS-Attacker    文件:RandomKeyGeneratorHelper.java   
public static AsymmetricCipherKeyPair generateECPublicKey() {

        // Should we also generate random curves?
        X9ECParameters ecp = SECNamedCurves.getByName(getRandomCurveName());
        ECKeyPairGenerator keygen = new ECKeyPairGenerator();
        ECDomainParameters domainParams = new ECDomainParameters(ecp.getCurve(), ecp.getG(), ecp.getN(), ecp.getH(),
                ecp.getSeed());
        keygen.init(new ECKeyGenerationParameters(domainParams, RandomHelper.getBadSecureRandom()));
        return keygen.generateKeyPair();
    }
项目:TLS-Attacker    文件:ECDHEServerKeyExchangePreparator.java   
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();
}
项目:gwt-crypto    文件:TlsDHUtils.java   
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();
}
项目:gwt-crypto    文件:TlsDHUtils.java   
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();
}
项目:gwt-crypto    文件:TlsECCUtils.java   
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();
}
项目:gwt-crypto    文件:DHAgreement.java   
/**
 * calculate our initial message.
 */
public BigInteger calculateMessage()
{
    DHKeyPairGenerator dhGen = new DHKeyPairGenerator();
    dhGen.init(new DHKeyGenerationParameters(random, dhParams));
    AsymmetricCipherKeyPair dhPair = dhGen.generateKeyPair();

    this.privateValue = ((DHPrivateKeyParameters)dhPair.getPrivate()).getX();

    return ((DHPublicKeyParameters)dhPair.getPublic()).getY();
}