diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/.gitignore @@ -0,0 +1,29 @@ +### IntelliJ IDEA ### +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/artifacts/sha512256_jar.xml b/.idea/artifacts/sha512256_jar.xml new file mode 100644 index 0000000..da25d6f --- /dev/null +++ b/.idea/artifacts/sha512256_jar.xml @@ -0,0 +1,9 @@ + + + $PROJECT_DIR$/out/artifacts/sha512256_jar + + + + + + \ No newline at end of file diff --git a/.idea/libraries/bcprov_lts8on_2_73_3.xml b/.idea/libraries/bcprov_lts8on_2_73_3.xml new file mode 100644 index 0000000..59b806f --- /dev/null +++ b/.idea/libraries/bcprov_lts8on_2_73_3.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..07115cd --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..e0a48c0 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..2ce3ba5 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 Kopjra + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..aa1a4ef --- /dev/null +++ b/README.md @@ -0,0 +1,10 @@ +# sha512256 +A simple Java CLI tool that calculates SHA-512/256 of a file. + +It uses the default Java Security library provider or, if unavailable, BouncyCastle (an open source library). + +## Requirements +* Java 8+ + +## Usage +`java -jar sha512256.jar filepath.ext` \ No newline at end of file diff --git a/lib/bcprov_lts8on_2_73_3/LICENSE b/lib/bcprov_lts8on_2_73_3/LICENSE new file mode 100644 index 0000000..a6bff8b --- /dev/null +++ b/lib/bcprov_lts8on_2_73_3/LICENSE @@ -0,0 +1,7 @@ +Copyright (c) 2000 - 2023 The Legion of the Bouncy Castle Inc. (https://www.bouncycastle.org) + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/lib/bcprov_lts8on_2_73_3/bcprov-lts8on-2.73.3.jar b/lib/bcprov_lts8on_2_73_3/bcprov-lts8on-2.73.3.jar new file mode 100644 index 0000000..3390dba Binary files /dev/null and b/lib/bcprov_lts8on_2_73_3/bcprov-lts8on-2.73.3.jar differ diff --git a/sha512256.iml b/sha512256.iml new file mode 100644 index 0000000..e72a6f7 --- /dev/null +++ b/sha512256.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/src/META-INF/MANIFEST.MF b/src/META-INF/MANIFEST.MF new file mode 100644 index 0000000..37197ef --- /dev/null +++ b/src/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Main-Class: Main + diff --git a/src/Main.java b/src/Main.java new file mode 100644 index 0000000..ed0a47c --- /dev/null +++ b/src/Main.java @@ -0,0 +1,42 @@ +import org.bouncycastle.jce.provider.BouncyCastleProvider; +import org.bouncycastle.util.encoders.Hex; + +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.security.Security; + +public class Main { + public static void main(String[] args) { + if (args.length != 1) { + System.out.println("Please provide input files"); + System.exit(1); + } + String inputFile = args[0]; + Security.addProvider(new BouncyCastleProvider()); + + try ( + InputStream inputStream = new FileInputStream(inputFile); + ) { + int byteRead; + byte[] byteBuffer = new byte[8192]; + + MessageDigest md = MessageDigest.getInstance("SHA-512/256"); + + while ((byteRead = inputStream.read(byteBuffer)) > 0) { + md.update(byteBuffer, 0, byteRead); + } + + String hex = new String(Hex.encode(md.digest())); + System.out.println(hex); + } catch (NoSuchAlgorithmException ex) { + ex.printStackTrace(); + System.exit(2); + } catch (IOException ex) { + ex.printStackTrace(); + System.exit(3); + } + } +} \ No newline at end of file