-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added scripts for hashing an input file
- Loading branch information
1 parent
dca04b7
commit 9bfa885
Showing
4 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/bin/env bash | ||
# ----------------------------------------------------------------------------- | ||
# This script can be used to hash the pool meta-data json file. | ||
# | ||
# Usage: ./hashFile.sh path_to_file | ||
# ----------------------------------------------------------------------------- | ||
TOOLS_JAR=Tools.jar | ||
|
||
file_path="$1" | ||
|
||
if [ $# -ne 1 ] | ||
then | ||
echo "Invalid number of parameters." | ||
echo "Usage: ./hashFile.sh path_to_file" | ||
exit 1 | ||
fi | ||
|
||
hash="$(java -cp $TOOLS_JAR cli.HashFile "$file_path")" | ||
echo "Meta-data content hash:" | ||
echo "$hash" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package cli; | ||
|
||
import net.i2p.crypto.eddsa.Utils; | ||
import support.Blake2b; | ||
|
||
import java.io.File; | ||
import java.nio.file.Files; | ||
|
||
public class HashFile { | ||
|
||
public static void main(String[] args) throws Exception { | ||
if (0 == args.length) { | ||
System.err.println("Usage: cli.HashFile FILE_PATH"); | ||
System.exit(1); | ||
} | ||
|
||
byte[] fileBytes = Files.readAllBytes(new File(args[0]).toPath()); | ||
|
||
byte[] hash = blake2b(fileBytes); | ||
System.out.println("0x" + Utils.bytesToHex(hash)); | ||
} | ||
|
||
public static byte[] blake2b(byte[] msg) { | ||
Blake2b digest = Blake2b.Digest.newInstance(32); | ||
digest.update(msg); | ||
return digest.digest(); | ||
} | ||
} |