Package java.security

Examples of java.security.KeyPair


  public byte[] createPublicKey() throws CryptoException {
    try {
      KeyPairGenerator keyGen = KeyPairGenerator.getInstance(ALGORITHM);
      keyGen.initialize(DH_SPEC);
      KeyPair keypair = keyGen.generateKeyPair();

      privateKey = keypair.getPrivate();
      PublicKey publicKey = keypair.getPublic();

      return publicKey.getEncoded();
    } catch (NoSuchAlgorithmException e) {
      throw new CryptoException(e);
    } catch (InvalidAlgorithmParameterException e) {
View Full Code Here


  {
    KeyPairGenerator  kg = KeyPairGenerator.getInstance( "RSA" );
   
    kg.initialize(strength, RandomUtils.SECURE_RANDOM );

    KeyPair pair = kg.generateKeyPair();
         
    X509V3CertificateGenerator certificateGenerator =
      new X509V3CertificateGenerator();
   
    certificateGenerator.setSignatureAlgorithm( "MD5WithRSAEncryption" );
   
    certificateGenerator.setSerialNumber( new BigInteger( ""+SystemTime.getCurrentTime()));
         
    X509Name  issuer_dn = new X509Name(true,cert_dn);
   
    certificateGenerator.setIssuerDN(issuer_dn);
   
    X509Name  subject_dn = new X509Name(true,cert_dn);
   
    certificateGenerator.setSubjectDN(subject_dn);
   
    Calendar  not_after = Calendar.getInstance();
   
    not_after.add(Calendar.YEAR, 1);
   
    certificateGenerator.setNotAfter( not_after.getTime());
   
    certificateGenerator.setNotBefore(Calendar.getInstance().getTime());
   
    certificateGenerator.setPublicKey( pair.getPublic());
   
    X509Certificate certificate = certificateGenerator.generateX509Certificate(pair.getPrivate());
   
    java.security.cert.Certificate[] certChain = {(java.security.cert.Certificate) certificate };

    manager.addCertToKeyStore( alias, pair.getPrivate(), certChain );
   
    return( certificate );
  }
View Full Code Here

            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));
        }
View Full Code Here

  initCrypto()
 
    throws IOException
  {
    try{
          KeyPair key_pair = generateDHKeyPair( transport, outbound );
           
          key_agreement = KeyAgreement.getInstance("DH");
         
          key_agreement.init(key_pair.getPrivate());
        
          DHPublicKey  dh_public_key = (DHPublicKey)key_pair.getPublic();
         
          BigInteger  dh_y = dh_public_key.getY();
         
          dh_public_key_bytes = bigIntegerToBytes( dh_y, DH_SIZE_BYTES );
         
View Full Code Here

        }
       
        last_dh_incoming_key_generate = now;
      }
     
      KeyPair  res = dh_key_generator.generateKeyPair();
     
      return( res );
    }
  }
View Full Code Here

    try{
      synchronized( this ){
       
        if ( use_method_public_key == null || use_method_private_key == null ){
         
          KeyPair  keys = CryptoECCUtils.createKeys();
         
          use_method_public_key  = keys.getPublic();
         
          use_method_private_key  = keys.getPrivate();
         
          last_unlock_time = SystemTime.getCurrentTime();
         
          COConfigurationManager.setParameter( CONFIG_PREFIX + "publickey", CryptoECCUtils.keyToRawdata( use_method_public_key ));
         
View Full Code Here

    add_time      = SystemTime.getCurrentTime();
   
    is_subscribed    = true;

    try{
      KeyPair  kp = CryptoECCUtils.createKeys();
       
      public_key       = CryptoECCUtils.keyToRawdata( kp.getPublic());
      private_key     = CryptoECCUtils.keyToRawdata( kp.getPrivate());
           
     
      fixed_random  = new Random().nextInt();
     
      init();
View Full Code Here

     
      byte[]  encoded_subs = Base64.encode( bytes );
     
        // use a transient key-pair as we won't have the private key in general
     
      KeyPair  kp = CryptoECCUtils.createKeys();
     
      byte[] public_key     = CryptoECCUtils.keyToRawdata( kp.getPublic());
      byte[] private_key     = CryptoECCUtils.keyToRawdata( kp.getPrivate());
 
      PlatformSubscriptionsMessenger.updateSubscription(
          true,
          subs.getName(),
          public_key,
View Full Code Here

    public void testGenerateKeyPairSha1Default()
    {
        DHParameterSpec parameterSpec = DiffieHellmanSession.getDefaultParameter();

        KeyPair keyPair = DiffieHellmanSession.generateKeyPair(parameterSpec);

        assertNotNull(keyPair);
    }
View Full Code Here

    public void testGenerateKeyPairSha1Random()
    {
        DHParameterSpec parameterSpec = DiffieHellmanSession.generateRandomParameter(512, 256);

        KeyPair keyPair = DiffieHellmanSession.generateKeyPair(parameterSpec);

        assertNotNull(keyPair);
    }
View Full Code Here

TOP

Related Classes of java.security.KeyPair

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.