Ejemplo n.º 1
0
  public boolean changePassword(String oldPassword, String newPassword) throws Exception {
    PrivateKey priv;

    try {
      priv = PubkeyUtils.decodePrivate(getPrivateKey(), getType(), oldPassword);
    } catch (Exception e) {
      return false;
    }

    setPrivateKey(PubkeyUtils.getEncodedPrivate(priv, newPassword));
    setEncrypted(newPassword.length() > 0);

    return true;
  }
Ejemplo n.º 2
0
  public String getDescription() {
    if (description == null) {
      final StringBuilder sb = new StringBuilder();
      try {
        final PublicKey pubKey = PubkeyUtils.decodePublic(publicKey, type);
        if (PubkeyDatabase.KEY_TYPE_RSA.equals(type)) {
          int bits = ((RSAPublicKey) pubKey).getModulus().bitLength();
          sb.append("RSA ");
          sb.append(bits);
          sb.append("-bit");
        } else if (PubkeyDatabase.KEY_TYPE_DSA.equals(type)) {
          sb.append("DSA 1024-bit");
        } else if (PubkeyDatabase.KEY_TYPE_EC.equals(type)) {
          int bits = ((ECPublicKey) pubKey).getParams().getCurve().getField().getFieldSize();
          sb.append("EC ");
          sb.append(bits);
          sb.append("-bit");
        } else {
          sb.append("Unknown Key Type");
        }
      } catch (NoSuchAlgorithmException e) {
        sb.append("Unknown Key Type");
      } catch (InvalidKeySpecException e) {
        sb.append("Unknown Key Type");
      }

      if (encrypted) sb.append(" (encrypted)");

      description = sb.toString();
    }
    return description;
  }