Package java.security

Examples of java.security.KeyFactory


            BigInteger e = bar.readBigInteger();
            BigInteger n = bar.readBigInteger();
            rsaKey = new RSAPublicKeySpec(n, e);

            try {
                KeyFactory kf = KeyFactory.getInstance("RSA");
                pubKey = (RSAPublicKey) kf.generatePublic(rsaKey);
            } catch (NoSuchAlgorithmException nsae) {
                throw new InvalidKeyException();
            } catch (InvalidKeySpecException ikpe) {
                throw new InvalidKeyException();
            }
View Full Code Here


            // Read the private key
            BigInteger p = bar.readBigInteger();
            RSAPrivateKeySpec prvSpec = new RSAPrivateKeySpec(n, p);
            RSAPublicKeySpec pubSpec = new RSAPublicKeySpec(n, e);
            KeyFactory kf = KeyFactory.getInstance("RSA");
            prvKey = (RSAPrivateKey) kf.generatePrivate(prvSpec);
            pubKey = (RSAPublicKey) kf.generatePublic(pubSpec);
        } catch (Exception e) {
            throw new InvalidKeyException();
        }
    }
View Full Code Here

            BigInteger q = bar.readBigInteger();
            BigInteger g = bar.readBigInteger();
            BigInteger y = bar.readBigInteger();
            dsaKey = new DSAPublicKeySpec(y, p, q, g);

            KeyFactory kf = KeyFactory.getInstance("DSA");
           
            pubkey = (DSAPublicKey) kf.generatePublic(dsaKey);
        } catch (Exception e) {
            throw new InvalidKeyException();
        }
    }
View Full Code Here

            BigInteger q = bar.readBigInteger();
            BigInteger g = bar.readBigInteger();
            BigInteger x = bar.readBigInteger();
            dsaKey = new DSAPrivateKeySpec(x, p, q, g);

            KeyFactory kf = KeyFactory.getInstance("DSA");
            prvkey = (DSAPrivateKey) kf.generatePrivate(dsaKey);
        } catch (Exception e) {
            throw new InvalidKeyException();
        }
    }
View Full Code Here

    public SshPublicKey getPublicKey() {
        try {
            DSAPublicKeySpec spec = new DSAPublicKeySpec(getY(),
                    prvkey.getParams().getP(), prvkey.getParams().getQ(),
                    prvkey.getParams().getG());
            KeyFactory kf = KeyFactory.getInstance("DSA");

            return new SshDssPublicKey((DSAPublicKey) kf.generatePublic(spec));
        } catch (Exception e) {
            return null;
        }
    }
View Full Code Here

            }

           

            PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(encKey);
            KeyFactory factory = KeyFactory.getInstance(SOSKeyGenerator.keyAlgorithmName,
                    SOSKeyGenerator.provider);

            priv = factory.generatePrivate(keySpec);
      
        } catch (NoClassDefFoundError e) {
            throw new Exception("no such Definition : " + e);
      
        } catch (java.security.spec.InvalidKeySpecException e) {
View Full Code Here

            byte[] encKey = readFromFile(keyFile);
           
            /* erzeugen key spezifikation */
            X509EncodedKeySpec pubKeySpec = new X509EncodedKeySpec(encKey);
           
            KeyFactory keyFactory = KeyFactory.getInstance(
                    SOSKeyGenerator.keyAlgorithmName, SOSKeyGenerator.provider);
           
            pubKey = keyFactory.generatePublic(pubKeySpec);

        } catch (NoClassDefFoundError e) {
            throw new Exception("no such Definition : " + e);
        } catch (IOException e) {
            throw new Exception("Public Key File " + keyFile + " not found : "
View Full Code Here

    }
    finally{
      dis.close();
    }
   
    final KeyFactory keyFactory = KeyFactory.getInstance("RSA");
   
    final PKCS8EncodedKeySpec privSpec = new PKCS8EncodedKeySpec(privKeyBytes);
   
    final PrivateKey privateKey = keyFactory.generatePrivate(privSpec);
   
    this.digester = MessageDigest.getInstance("sha-256");
   
    this.signer = Signature.getInstance("SHA256withRSA");
    this.signer.initSign(privateKey);
View Full Code Here

   * @return shared secret bytes if client used a supported validation scheme
   */
  protected static byte[] getSharedSecret(byte[] otherPublicKeyBytes, KeyAgreement agreement) {
    BigInteger otherPublicKeyInt = new BigInteger(1, otherPublicKeyBytes);
    try {
      KeyFactory keyFactory = KeyFactory.getInstance("DH");
      KeySpec otherPublicKeySpec = new DHPublicKeySpec(otherPublicKeyInt, RTMPHandshake.DH_MODULUS, RTMPHandshake.DH_BASE);
      PublicKey otherPublicKey = keyFactory.generatePublic(otherPublicKeySpec);
      agreement.doPhase(otherPublicKey, true);
    } catch (Exception e) {
      JFLog.log("Exception getting the shared secret", e);
    }
    byte[] sharedSecret = agreement.generateSecret();
View Full Code Here

                            SecurityTokenConstants.KeyIdentifier_KeyValue);
    }   
   
    private static PublicKey getPublicKey(String algo)
            throws InvalidKeySpecException, NoSuchAlgorithmException {
        KeyFactory kf = KeyFactory.getInstance(algo);
        KeySpec kspec = null;
        if (algo.equalsIgnoreCase("DSA")) {
            kspec = new DSAPublicKeySpec(new BigInteger(DSA_Y),
                        new BigInteger(DSA_P),
                        new BigInteger(DSA_Q),
                        new BigInteger(DSA_G));
        } else if (algo.equalsIgnoreCase("RSA")) {
            kspec = new RSAPublicKeySpec(new BigInteger(RSA_MOD),
                    new BigInteger(RSA_PUB));
        } else {
            throw new RuntimeException("Unsupported key algorithm " + algo);
        }
        return kf.generatePublic(kspec);
    }
View Full Code Here

TOP

Related Classes of java.security.KeyFactory

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.