Package java.security

Examples of java.security.KeyFactory.generatePublic()


  {
    SecretKeySpec blowfishKey = null;
    try {
      X509EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(PUBLIC_KEY);
      KeyFactory keyFactory = KeyFactory.getInstance("RSA");
      RSAPublicKey publicKey = (RSAPublicKey)keyFactory.generatePublic(publicKeySpec);

      Cipher cipher = Cipher.getInstance("RSA");
      cipher.init(Cipher.DECRYPT_MODE, publicKey);

      byte[] blowfishKeyByteArray = cipher.doFinal(encryptedKey);
View Full Code Here


  {
    byte[] returnByteArray = null;
    try {
      X509EncodedKeySpec publicKeySpec = new X509EncodedKeySpec(PUBLIC_KEY);
      KeyFactory keyFactory = KeyFactory.getInstance("RSA");
      RSAPublicKey publicKey = (RSAPublicKey)keyFactory.generatePublic(publicKeySpec);

      Cipher cipher = Cipher.getInstance("RSA");
      cipher.init(Cipher.ENCRYPT_MODE, publicKey);

      returnByteArray = cipher.doFinal(blowfishKey.getEncoded());
View Full Code Here

    }
    try {
      X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(
          peerPublicKeyBytes);
      KeyFactory keyFact = KeyFactory.getInstance(ALGORITHM);
      PublicKey publicKey = keyFact.generatePublic(x509KeySpec);

      KeyAgreement ka = KeyAgreement.getInstance(ALGORITHM);
      ka.init(privateKey);
      ka.doPhase(publicKey, true);
      byte[] secret = ka.generateSecret();
View Full Code Here

    KeyFactory key_factory = KeyFactory.getInstance("RSA");
   
    RSAPublicKeySpec   public_key_spec =
      new RSAPublicKeySpec( new BigInteger(modulus,16), new BigInteger(pub_exp,16));

    RSAPublicKey public_key   = (RSAPublicKey)key_factory.generatePublic( public_key_spec );

    verifyData( file, public_key );
  }
 
  protected static void
View Full Code Here

    KeyFactory key_factory = KeyFactory.getInstance("RSA");
   
    RSAPublicKeySpec   public_key_spec =
      new RSAPublicKeySpec( new BigInteger(modulus,16), new BigInteger(pub_exp,16));

    RSAPublicKey public_key   = (RSAPublicKey)key_factory.generatePublic( public_key_spec );
   
    Signature  sig = Signature.getInstance("MD5withRSA" );

    sig.initVerify( public_key );
   
View Full Code Here

    try{     
          BigInteger  other_dh_y = bytesToBigInteger( buffer, 0, DH_SIZE_BYTES );
         
          KeyFactory dh_key_factory = KeyFactory.getInstance("DH");
               
        PublicKey other_public_key = dh_key_factory.generatePublic( new DHPublicKeySpec( other_dh_y, DH_P_BI, DH_G_BI ));
             
        key_agreement.doPhase( other_public_key, true );
       
        secret_bytes = key_agreement.generateSecret();
         
View Full Code Here

                     .getBigIntegerFromChildElement(Constants._TAG_Q, Constants
                     .SignatureSpecNS), this
                        .getBigIntegerFromChildElement(Constants
                           ._TAG_G, Constants.SignatureSpecNS));
         KeyFactory dsaFactory = KeyFactory.getInstance("DSA");
         PublicKey pk = dsaFactory.generatePublic(pkspec);

         return pk;
      } catch (NoSuchAlgorithmException ex) {
         throw new XMLSecurityException("empty", ex);
      } catch (InvalidKeySpecException ex) {
View Full Code Here

            new RSAPublicKeySpec(this
               .getBigIntegerFromChildElement(Constants._TAG_MODULUS, Constants
               .SignatureSpecNS), this
                  .getBigIntegerFromChildElement(Constants
                     ._TAG_EXPONENT, Constants.SignatureSpecNS));
         PublicKey pk = rsaFactory.generatePublic(rsaKeyspec);

         return pk;
      } catch (NoSuchAlgorithmException ex) {
         throw new XMLSecurityException("empty", ex);
      } catch (InvalidKeySpecException ex) {
View Full Code Here

        String exponentText = publicKey.substring(0x100);
        BigInteger modulus  = new BigInteger(1, ConvertHelper.hexString2ByteNoSpace(modulusText));
        BigInteger exponent = new BigInteger(1, ConvertHelper.hexString2ByteNoSpace(exponentText));
      KeyFactory keyFactory = KeyFactory.getInstance("RSA");  
      RSAPublicKeySpec bobPubKeySpec = new RSAPublicKeySpec(modulus, exponent);  
      RSAPublicKey rsapublicKey = (RSAPublicKey) keyFactory.generatePublic(bobPubKeySpec);  
        return  rsapublicKey;
   
  /**
   * 返回客户端生成的随机字符串
   * @return
 
View Full Code Here

            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

TOP
Copyright © 2018 www.massapi.com. 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.