Package java.security

Examples of java.security.KeyPairGenerator


   */
  private int keySize = SymmetricCryptor.DEFAULT_KEY_BITS;

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


    String          cert_dn,
    int            strength )
 
    throws Exception
  {
    KeyPairGenerator  kg = KeyPairGenerator.getInstance( "RSA" );
   
    kg.initialize(strength, RandomUtils.SECURE_RANDOM );

    KeyPair pair = kg.generateKeyPair();
         
    X509V3CertificateGenerator certificateGenerator =
      new X509V3CertificateGenerator();
   
    certificateGenerator.setSignatureAlgorithm( "MD5WithRSAEncryption" );
View Full Code Here

 
    throws CryptoManagerException
  {
    try
    {
      KeyPairGenerator keyGen = KeyPairGenerator.getInstance("ECDSA", "BC");
     
      keyGen.initialize(ECCparam);

      return keyGen.genKeyPair();
     
    }catch(Throwable e){
     
      throw( new CryptoManagerException( "Failed to create keys", e ));
    }
View Full Code Here

     * @param bits
     */
    public void generate(int bits) {
        try {
            // Initialize the generator
            KeyPairGenerator keyGen = KeyPairGenerator.getInstance("RSA");
            keyGen.initialize(bits, Utils.getRND());

            KeyPair pair = keyGen.generateKeyPair();

            // Get the keys and set
            setPrivateKey(new SshRsaPrivateKey(
                    (RSAPrivateKey) pair.getPrivate(),
                    (RSAPublicKey) pair.getPublic()));
View Full Code Here

     * @param bits
     */
    public void generate(int bits) {
        try {
            // Initialize the generator
            KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA");
            keyGen.initialize(bits, Utils.getRND());

            KeyPair pair = keyGen.generateKeyPair();

            // Get the keys
            DSAPrivateKey prvKey = (DSAPrivateKey) pair.getPrivate();
            DSAPublicKey pubKey = (DSAPublicKey) pair.getPublic();

View Full Code Here

   }

   @Test
   public void testManualFail() throws Exception
   {
      KeyPairGenerator kpg = KeyPairGenerator.getInstance("RSA");
      kpg.initialize(1024);
      KeyPair keyPair = kpg.genKeyPair();

      Verifier verifier = new Verifier();
      Verification verification = verifier.addNew();
      verification.setKey(keyPair.getPublic());
View Full Code Here

 
  return sign.verify(signBuffer);
    }
   
    public KeyPair genKeyPair() throws NoSuchAlgorithmException {
  KeyPairGenerator kpg = KeyPairGenerator.getInstance(algorithm);
  kpg.initialize(bitkey);
  return kpg.generateKeyPair()
    }
View Full Code Here

                    && Security.getProvider("BC") == null) {
                Provider bp = new org.bouncycastle.jce.provider.BouncyCastleProvider();
                Security.addProvider(bp);
            }

            KeyPairGenerator generator = KeyPairGenerator.getInstance(
                    SOSKeyGenerator.keyAlgorithmName, SOSKeyGenerator.provider);
          
            //SecureRandom random = SecureRandom.getInstance("SHA1PRNG",
            // "SUN");
            //initialize(int keysize, SecureRandom random)

            generator.initialize(SOSKeyGenerator.keyLenght, new SecureRandom());
            //generator.initialize(this.keyLenght);

            KeyPair keys = generator.generateKeyPair();

            return keys;
        } catch (NoClassDefFoundError e) {
            throw new Exception("no such Definition : " + e);
        } catch (java.security.NoSuchProviderException e) {
View Full Code Here

   */
  protected KeyPair generateKeyPair() {
    KeyPair keyPair = null;
    DHParameterSpec keySpec = new DHParameterSpec(DH_MODULUS, DH_BASE);
    try {
      KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DH");
      keyGen.initialize(keySpec);
      keyPair = keyGen.generateKeyPair();
      keyAgreement = KeyAgreement.getInstance("DH");
      keyAgreement.init(keyPair.getPrivate());
    } catch (Exception e) {
      JFLog.log("Error generating keypair", e);
    }
View Full Code Here

                        "ie/baltimore/merlin-examples/merlin-xmlenc-five/plaintext.xml");
        DocumentBuilder builder = XMLUtils.createDocumentBuilder(false);
        Document document = builder.parse(sourceDocument);
       
        // Set up the Key
        KeyPairGenerator rsaKeygen = KeyPairGenerator.getInstance("RSA");
        KeyPair kp = rsaKeygen.generateKeyPair();
        PrivateKey priv = kp.getPrivate();
        PublicKey pub = kp.getPublic();

        // Generate a traffic key
        KeyGenerator keygen = KeyGenerator.getInstance("AES");
View Full Code Here

TOP

Related Classes of java.security.KeyPairGenerator

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.