Examples of PrivateKey


Examples of java.security.PrivateKey

    public Document sign(Document doc, KeyPair keyPair) {
        if (log.isTraceEnabled()) {
            log.tracef("Document to be signed={0}", new Object[]{SamlUtils.getDocumentAsString(doc)});
        }

        PrivateKey signingKey = keyPair.getPrivate();
        PublicKey publicKey = keyPair.getPublic();

        DOMSignContext dsc = new DOMSignContext(signingKey, doc.getDocumentElement());
        dsc.setDefaultNamespacePrefix("dsig");
View Full Code Here

Examples of java.security.PrivateKey

        InputStream keyStoreStream = getClass().getClassLoader().getResourceAsStream("test_keystore.jks");
        KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
        keyStore.load(keyStoreStream, "store456".toCharArray());
        X509Certificate certificate = (X509Certificate) keyStore.getCertificate("servercert");
        PublicKey publicKey = certificate.getPublicKey();
        PrivateKey privateKey = (PrivateKey) keyStore.getKey("servercert", "pass456".toCharArray());
        keyPair = new KeyPair(publicKey, privateKey);
    }
View Full Code Here

Examples of java.security.PrivateKey

      }

      @Override
      public void visitAsymetricUserKey(int userId, byte[] data) {
        if (userId == user.getId()) {
          PrivateKey privateKey = user.getPrivateKey();
          setSecretKey(decryptAsymetricKey(privateKey, data));
        }
      }
    };
    try {
View Full Code Here

Examples of java.security.PrivateKey

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

Examples of java.security.PrivateKey

  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.PrivateKey

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

Examples of java.security.PrivateKey

    }
  }

  public static PrivateKey loadPrivateKey(byte[] keyData) throws IOException {
    try {
      PrivateKey privateKey = deserializePrivateKey(keyData);
      return privateKey;
    } catch (Exception e) {
      ExceptionUtils.handleInterrupted(e);
      throw new IOException("Error while loading key", e);
    }
View Full Code Here

Examples of java.security.PrivateKey

      throw new IllegalArgumentException("Error reading certificate: " + certPath, e);
    }

    File keyPath = new File(base, alias + ".key");

    PrivateKey privateKey;
    try {
      privateKey = PrivateKeys.fromPem(keyPath);
    } catch (IOException e) {
      throw new IllegalArgumentException("Error reading private key: " + keyPath, e);
    }
View Full Code Here

Examples of java.security.PrivateKey

      name = name.replace(".pub", "");
      publicKeys.put(Integer.parseInt(name), publicKey);
    }

    for (File file : dir.listFiles(new FilenameEndsWithFilter(".private"))) {
      PrivateKey privateKey = RsaUtils.loadPrivateKey(file);
      String name = file.getName();
      name = name.replace(".private", "");
      privateKeys.put(Integer.parseInt(name), privateKey);
    }
  }
View Full Code Here

Examples of java.security.PrivateKey

  public GoogleComputeClient getComputeClient(GoogleCloud cloud) throws OpsException {
    KeyParser parser = new KeyParser();

    Object parsed = parser.parse(cloud.serviceAccountKey.plaintext());
    PrivateKey privateKey;
    if (parsed == null) {
      throw new OpsException("Cannot parse private key");
    } else if (parsed instanceof PrivateKey) {
      privateKey = (PrivateKey) parsed;
    } else {
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.