Examples of KeyFactory


Examples of java.security.KeyFactory

    }

    private PublicKey loadPublicKey(String filePath, String algorithm) throws Exception {
        String fileData = new String(JavaUtils.getBytesFromFile(getControlFilePath(filePath)));
        byte[] keyBytes = Base64.decode(fileData);
        KeyFactory kf = KeyFactory.getInstance(algorithm);
        X509EncodedKeySpec keySpec = new X509EncodedKeySpec(keyBytes);
        return kf.generatePublic(keySpec);
    }
View Full Code Here

Examples of java.security.KeyFactory

    }

    private PublicKey loadPublicKey(String filePath, String algorithm) throws Exception {
        String fileData = new String(JavaUtils.getBytesFromFile(getControlFilePath(filePath)));
        byte[] keyBytes = Base64.decode(fileData);
        KeyFactory kf = KeyFactory.getInstance(algorithm);
        X509EncodedKeySpec keySpec = new X509EncodedKeySpec(keyBytes);
        return kf.generatePublic(keySpec);
    }
View Full Code Here

Examples of java.security.KeyFactory

        byte[] pkcs8Bytes = JavaUtils.getBytesFromFile(filename);
        PKCS8EncodedKeySpec pkcs8Spec = new PKCS8EncodedKeySpec(pkcs8Bytes);

        // Create a key factory
        KeyFactory keyFactory = KeyFactory.getInstance("RSA");
        rsaKey = keyFactory.generatePrivate(pkcs8Spec);
    }
View Full Code Here

Examples of java.security.KeyFactory

         try {
            String identity = in.identity;
            String pem = in.credential;

            // extract private key
            KeyFactory keyFactory = KeyFactory.getInstance("RSA");
            PrivateKey privateKey = keyFactory.generatePrivate(Pems.privateKeySpec(Payloads.newStringPayload(pem)));

            // extract certificate(s)
            Collection<X509Certificate> certs = x509Certificates(pem);

            return new FGCPCredentials.Builder().identity(identity).credential(pem)
View Full Code Here

Examples of java.security.KeyFactory

     * @param pubKeyInfo SubjectPublicKeyInfo instance containing the public key information.
     */
    public static PublicKey getPublicKeyObject(SubjectPublicKeyInfo pubKeyInfo) throws Exception{
        RSAPublicKeyStructure pubkeyStruct = new RSAPublicKeyStructure((ASN1Sequence)pubKeyInfo.getPublicKey());
        RSAPublicKeySpec pubkeySpec = new RSAPublicKeySpec(pubkeyStruct.getModulus(), pubkeyStruct.getPublicExponent());
        KeyFactory keyFactory = KeyFactory.getInstance("RSA");
        PublicKey pubKey = keyFactory.generatePublic(pubkeySpec);
        return pubKey;
    }
View Full Code Here

Examples of java.security.KeyFactory

            return x.toJCEKeyPair();
        }
        if (key instanceof com.trilead.ssh2.signature.DSAPrivateKey) {
            com.trilead.ssh2.signature.DSAPrivateKey x = (com.trilead.ssh2.signature.DSAPrivateKey)key;
            KeyFactory kf = KeyFactory.getInstance("DSA");
//            System.out.println("ssh-dsa " + new String(Base64.encode(DSASHA1Verify.encodeSSHDSAPublicKey(x.getPublicKey()))));

            return new KeyPair(
                    kf.generatePublic(new DSAPublicKeySpec(x.getY(), x.getP(), x.getQ(), x.getG())),
                    kf.generatePrivate(new DSAPrivateKeySpec(x.getX(), x.getP(), x.getQ(), x.getG())));
        }

        throw new UnsupportedOperationException("Unrecognizable key format: "+key);
    }
View Full Code Here

Examples of java.security.KeyFactory

        PemReader reader = new PemReader(new StringReader(s));
        PemObject pemObject = reader.readPemObject();
        reader.close();

        PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(pemObject.getContent());
        KeyFactory kf = KeyFactory.getInstance("RSA");
        PrivateKey privateKey = kf.generatePrivate(keySpec);
        if (privateKey instanceof RSAPrivateCrtKey) {
          RSAPrivateCrtKey rsaPrivateCrtKey = (RSAPrivateCrtKey) privateKey;
          RSAPublicKeySpec publicKeySpec = new java.security.spec.RSAPublicKeySpec(
              rsaPrivateCrtKey.getModulus(), rsaPrivateCrtKey.getPublicExponent());
          PublicKey publicKey = kf.generatePublic(publicKeySpec);
          key = new KeyPair(publicKey, privateKey);
        } else {
          key = privateKey;
        }
      } catch (Exception e) {
View Full Code Here

Examples of java.security.KeyFactory

  private PrivateKey tryParsePemFormat(String data) {
    try {
      byte[] encoded = Base64.decode(data);
      PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(encoded);
      KeyFactory kf = KeyFactory.getInstance("RSA");
      PrivateKey privKey = kf.generatePrivate(keySpec);

      return privKey;
    } catch (Exception e) {
      log.debug("Error parsing pem data", e);
      return null;
View Full Code Here

Examples of java.security.KeyFactory

  }

  public static PublicKey deserializePublicKey(byte[] keyData) {
    X509EncodedKeySpec pubKeySpec = new X509EncodedKeySpec(keyData);

    KeyFactory keyFactory = getKeyFactory();

    PublicKey pubKey;
    try {
      pubKey = keyFactory.generatePublic(pubKeySpec);
    } catch (InvalidKeySpecException e) {
      throw new IllegalArgumentException("Error deserializing public key", e);
    }
    return pubKey;
  }
View Full Code Here

Examples of java.security.KeyFactory

  }

  public static PrivateKey deserializePrivateKey(byte[] keyData) {
    PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(keyData);

    KeyFactory keyFactory = getKeyFactory();

    PrivateKey privateKey;
    try {
      privateKey = keyFactory.generatePrivate(keySpec);
    } catch (InvalidKeySpecException e) {
      throw new IllegalArgumentException("Error deserializing private key", e);
    }
    return privateKey;
  }
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.