Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ This library is maintained by CodeDead. You can find more about us using the fol
* [Twitter](https://twitter.com/C0DEDEAD)
* [Facebook](https://facebook.com/deadlinecodedead)

Copyright © 2022 CodeDead
Copyright © 2023 CodeDead
26 changes: 13 additions & 13 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 31
buildToolsVersion '30.0.3'
compileSdk 34
defaultConfig {
applicationId "com.codedead.deadhash"
minSdkVersion 24
targetSdkVersion 31
versionName '1.7.8'
minSdk 28
targetSdk 34
versionName '1.8.0'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
versionCode 9
versionCode 10
}
buildTypes {
release {
Expand All @@ -20,20 +19,21 @@ android {
productFlavors {
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
namespace 'com.codedead.deadhash'
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
androidTestImplementation('androidx.test.espresso:espresso-core:3.4.0', {
androidTestImplementation('androidx.test.espresso:espresso-core:3.5.1', {
exclude group: 'com.android.support', module: 'support-annotations'
})
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.10.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.cardview:cardview:1.0.0'
implementation "androidx.preference:preference:1.2.0"
implementation 'androidx.preference:preference:1.2.1'
testImplementation 'junit:junit:4.13.2'
}
7 changes: 4 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.codedead.deadhash">
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />

<application
android:name=".main.Runner"
Expand Down
Binary file modified app/src/main/ic_launcher-playstore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed app/src/main/ic_launcher-web.png
Binary file not shown.
Binary file removed app/src/main/ic_launcher_round-web.png
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package com.codedead.deadhash.domain.objects.hashgenerator;

import android.content.ContentResolver;
import android.net.Uri;

import com.codedead.deadhash.domain.utils.HashUtil;

import java.util.List;

public final class FileHashGenerator extends HashGenerator {

private final Uri uri;
private final ContentResolver contentResolver;

/**
* Initialize a new HashGenerator
*
* @param uri The Uri of the file that should be hashed
* @param hashAlgorithms The List of HashingAlgorithm enums that should be used to calculate hashes
* @param compare The compare String for the calculated hashes
*/
public FileHashGenerator(final Uri uri, final ContentResolver contentResolver, final List<HashAlgorithm> hashAlgorithms, final String compare) {
super(hashAlgorithms, compare);

if (uri == null)
throw new NullPointerException("File cannot be null!");
if (contentResolver == null)
throw new NullPointerException("ContentResolver cannot be null!");

this.uri = uri;
this.contentResolver = contentResolver;
}

/**
* Generate the List of HashData for the given input data
*
* @return The List of HashData for the given input data
*/
@Override
public List<HashData> generateHashes() {
for (final HashAlgorithm algorithm : super.getHashAlgorithms()) {
switch (algorithm) {
case md5 -> {
final String md5 = HashUtil.calculateHash(uri, contentResolver, "MD5");
getHashData().add(new HashData("MD5", md5, getCompare()));
}
case sha1 -> {
final String sha1 = HashUtil.calculateHash(uri, contentResolver, "SHA-1");
getHashData().add(new HashData("SHA-1", sha1, getCompare()));
}
case sha224 -> {
final String sha224 = HashUtil.calculateHash(uri, contentResolver, "SHA-224");
getHashData().add(new HashData("SHA-224", sha224, getCompare()));
}
case sha256 -> {
final String sha256 = HashUtil.calculateHash(uri, contentResolver, "SHA-256");
getHashData().add(new HashData("SHA-256", sha256, getCompare()));
}
case sha384 -> {
final String sha384 = HashUtil.calculateHash(uri, contentResolver, "SHA-384");
getHashData().add(new HashData("SHA-384", sha384, getCompare()));
}
case sha512 -> {
final String sha512 = HashUtil.calculateHash(uri, contentResolver, "SHA-512");
getHashData().add(new HashData("SHA-512", sha512, getCompare()));
}
case crc32 -> {
final String crc32 = HashUtil.calculateCRC32(uri, contentResolver);
getHashData().add(new HashData("CRC32", crc32, getCompare()));
}
}
}

return getHashData();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class HashData implements Parcelable {

private final String compareCheck;

public static final Creator<HashData> CREATOR = new Creator<HashData>() {
public static final Creator<HashData> CREATOR = new Creator<>() {
@Override
public HashData createFromParcel(final Parcel in) {
return new HashData(in);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,117 +1,49 @@
package com.codedead.deadhash.domain.objects.hashgenerator;

import com.codedead.deadhash.domain.utils.HashUtil;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public final class HashGenerator {

private final byte[] data;
public abstract class HashGenerator implements IHashGenerator {
private final List<HashAlgorithm> hashAlgorithms;
private final List<HashData> hashData;
private final String compare;

/**
* Initialize a new HashGenerator
*
* @param data The byte array that should be hashed
* @param hashAlgorithms The List of HashingAlgorithm enums that should be used to calculate hashes
* @param compare The compare String for the calculated hashes
*/
public HashGenerator(final byte[] data, final List<HashAlgorithm> hashAlgorithms, final String compare) {
public HashGenerator(final List<HashAlgorithm> hashAlgorithms, final String compare) {
hashData = new ArrayList<>();
this.data = data;

this.hashAlgorithms = hashAlgorithms;
this.compare = compare;
}

/**
* Initialize a new HashGenerator
* Get the List of HashData for the given input data
*
* @param data The byte array that should be hashed
* @param hashAlgorithms The List of HashingAlgorithm enums that should be used to calculate hashes
* @param compare The compare String for the calculated hashes
* @throws IOException When the File could not be read
* @return The List of HashData for the given input data
*/
public HashGenerator(final File data, final List<HashAlgorithm> hashAlgorithms, final String compare) throws IOException {
hashData = new ArrayList<>();
this.data = readFileToBytes(data);
this.hashAlgorithms = hashAlgorithms;
this.compare = compare;
public List<HashAlgorithm> getHashAlgorithms() {
return hashAlgorithms;
}

/**
* Read a file and return a byte array that represents the given File
* Get the List of HashData for the given input data
*
* @param file The File that should be read
* @return The byte array that represents the given File
* @throws IOException When the File could not be read
* @return The List of HashData for the given input data
*/
private byte[] readFileToBytes(final File file) throws IOException {
if (file == null)
throw new NullPointerException("File cannot be null!");

final int size = (int) file.length();
final byte[] bytes = new byte[size];
final byte[] tmpBuff = new byte[size];
try (final FileInputStream fis = new FileInputStream(file)) {
int read = fis.read(bytes, 0, size);
if (read < size) {
int remain = size - read;
while (remain > 0) {
read = fis.read(tmpBuff, 0, remain);
System.arraycopy(tmpBuff, 0, bytes, size - remain, read);
remain -= read;
}
}
}

return bytes;
public List<HashData> getHashData() {
return hashData;
}

/**
* Generate the List of HashData for the given input data
* @return The List of HashData for the given input data
* Get the compare String for the calculated hashes
*
* @return The compare String for the calculated hashes
*/
public final List<HashData> generateHashes() {
for (final HashAlgorithm algorithm : hashAlgorithms) {
switch (algorithm) {
case md5:
final String md5 = HashUtil.calculateHash(data, "MD5");
hashData.add(new HashData("MD5", md5, compare));
break;
case sha1:
final String sha1 = HashUtil.calculateHash(data, "SHA-1");
hashData.add(new HashData("SHA-1", sha1, compare));
break;
case sha224:
final String sha224 = HashUtil.calculateHash(data, "SHA-224");
hashData.add(new HashData("SHA-224", sha224, compare));
break;
case sha256:
final String sha256 = HashUtil.calculateHash(data, "SHA-256");
hashData.add(new HashData("SHA-256", sha256, compare));
break;
case sha384:
final String sha384 = HashUtil.calculateHash(data, "SHA-384");
hashData.add(new HashData("SHA-384", sha384, compare));
break;
case sha512:
final String sha512 = HashUtil.calculateHash(data, "SHA-512");
hashData.add(new HashData("SHA-512", sha512, compare));
break;
case crc32:
final String crc32 = HashUtil.calculateCRC32(data);
hashData.add(new HashData("CRC32", crc32, compare));
break;
}
}

return hashData;
public String getCompare() {
return compare;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.codedead.deadhash.domain.objects.hashgenerator;

import java.util.List;

public interface IHashGenerator {
List<HashData> generateHashes();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.codedead.deadhash.domain.objects.hashgenerator;

import com.codedead.deadhash.domain.utils.HashUtil;

import java.util.List;

public final class TextHashGenerator extends HashGenerator {

private final String data;

/**
* Initialize a new TextHashGenerator
*
* @param data The String that should be hashed
* @param hashAlgorithms The List of HashingAlgorithm enums that should be used to calculate hashes
* @param compare The compare String for the calculated hashes
*/
public TextHashGenerator(final String data, List<HashAlgorithm> hashAlgorithms, String compare) {
super(hashAlgorithms, compare);

if (data == null)
throw new NullPointerException("Data cannot be null!");
if (data.isEmpty())
throw new IllegalArgumentException("Data cannot be empty!");

this.data = data;
}

/**
* Generate the List of HashData for the given input data
*
* @return The List of HashData for the given input data
*/
@Override
public List<HashData> generateHashes() {
for (final HashAlgorithm algorithm : super.getHashAlgorithms()) {
switch (algorithm) {
case md5 -> {
final String md5 = HashUtil.calculateHash(data.getBytes(), "MD5");
getHashData().add(new HashData("MD5", md5, getCompare()));
}
case sha1 -> {
final String sha1 = HashUtil.calculateHash(data.getBytes(), "SHA-1");
getHashData().add(new HashData("SHA-1", sha1, getCompare()));
}
case sha224 -> {
final String sha224 = HashUtil.calculateHash(data.getBytes(), "SHA-224");
getHashData().add(new HashData("SHA-224", sha224, getCompare()));
}
case sha256 -> {
final String sha256 = HashUtil.calculateHash(data.getBytes(), "SHA-256");
getHashData().add(new HashData("SHA-256", sha256, getCompare()));
}
case sha384 -> {
final String sha384 = HashUtil.calculateHash(data.getBytes(), "SHA-384");
getHashData().add(new HashData("SHA-384", sha384, getCompare()));
}
case sha512 -> {
final String sha512 = HashUtil.calculateHash(data.getBytes(), "SHA-512");
getHashData().add(new HashData("SHA-512", sha512, getCompare()));
}
case crc32 -> {
final String crc32 = HashUtil.calculateCRC32(data.getBytes());
getHashData().add(new HashData("CRC32", crc32, getCompare()));
}
}
}

return getHashData();
}
}
Loading