Example #1
0
 /**
  * Creates and returns a {@link Digest} instance corresponding to the given algorithm.
  *
  * @param algorithm the digest algorithm.
  * @return the created {@link Digest} instance.
  * @throws NullPointerException if {@code algorithm} is {@code null}.
  * @throws IllegalArgumentException if the given algorithm is unknown.
  */
 static Digest newDigest(Algorithm<Digest> algorithm) {
   Parameters.checkNotNull(algorithm);
   Digest digest;
   if (algorithm == Algorithm.MD2) {
     digest = Digests.md2();
   } else if (algorithm == Algorithm.MD4) {
     digest = Digests.md4();
   } else if (algorithm == Algorithm.MD5) {
     digest = Digests.md5();
   } else if (algorithm == Algorithm.SHA1) {
     digest = Digests.sha1();
   } else if (algorithm == Algorithm.SHA256) {
     digest = Digests.sha256();
   } else if (algorithm == Algorithm.SHA512) {
     digest = Digests.sha512();
   } else if (algorithm == Algorithm.KECCAK224) {
     digest = Digests.keccak224();
   } else if (algorithm == Algorithm.KECCAK256) {
     digest = Digests.keccak256();
   } else if (algorithm == Algorithm.KECCAK384) {
     digest = Digests.keccak384();
   } else if (algorithm == Algorithm.KECCAK512) {
     digest = Digests.keccak512();
   } else {
     throw new IllegalArgumentException("Unknown algorithm");
   }
   return digest;
 }
Example #2
0
  private void SetKey(byte[] pbPasswordUtf8) {
    assert pbPasswordUtf8 != null;
    if (pbPasswordUtf8 == null) throw new IllegalArgumentException("pbPasswordUtf8");

    byte[] pbRaw = Digests.sha256(pbPasswordUtf8);

    m_psPassword = new ProtectedString(true, pbPasswordUtf8);
    m_pbKeyData = new ProtectedBinary(true, pbRaw);
  }
  private void complete() {
    status = STATUS_COMPLETE;
    manager.incrementDownloadsToReview();

    if (completeFile.getAbsoluteFile().exists()) {
      Librarian.instance().scan(getSavePath().getAbsoluteFile());
      String sha1 = Digests.sha1(completeFile);
      Engine.instance().notifyDownloadFinished(getDisplayName(), completeFile, sha1);
    } else {
      Engine.instance().notifyDownloadFinished(getDisplayName(), getSavePath());
    }

    cleanupIncomplete();
  }