Пример #1
0
  /** @return success */
  private static final boolean genKeysCLI(String publicKeyFile, String privateKeyFile) {
    FileOutputStream fileOutputStream = null;

    I2PAppContext context = I2PAppContext.getGlobalContext();
    try {
      Object signingKeypair[] = context.keyGenerator().generateSigningKeypair();
      SigningPublicKey signingPublicKey = (SigningPublicKey) signingKeypair[0];
      SigningPrivateKey signingPrivateKey = (SigningPrivateKey) signingKeypair[1];

      fileOutputStream = new FileOutputStream(publicKeyFile);
      signingPublicKey.writeBytes(fileOutputStream);
      fileOutputStream.close();
      fileOutputStream = null;

      fileOutputStream = new FileOutputStream(privateKeyFile);
      signingPrivateKey.writeBytes(fileOutputStream);

      System.out.println("\r\nPrivate key written to: " + privateKeyFile);
      System.out.println("Public key written to: " + publicKeyFile);
      System.out.println("\r\nPublic key: " + signingPublicKey.toBase64() + "\r\n");
    } catch (Exception e) {
      System.err.println("Error writing keys:");
      e.printStackTrace();
      return false;
    } finally {
      if (fileOutputStream != null)
        try {
          fileOutputStream.close();
        } catch (IOException ioe) {
        }
    }
    return true;
  }
Пример #2
0
  /**
   * Fetches the trusted keys for the current instance. We could sort it but don't bother.
   *
   * @return A <code>String</code> containing the trusted keys, delimited by CR LF line breaks.
   */
  public String getTrustedKeysString() {
    StringBuilder buf = new StringBuilder(1024);
    for (SigningPublicKey spk : _trustedKeys.keySet()) {
      // If something already buffered, first add line break.
      if (buf.length() > 0) buf.append("\r\n");
      buf.append(spk.toBase64());
    }

    return buf.toString();
  }