Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
FIT-Connect-SDK - Java
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
FIT-Connect
FIT-Connect-SDK - Java
Commits
5a691ec3
Commit
5a691ec3
authored
2 years ago
by
Martin Vogel
Browse files
Options
Downloads
Patches
Plain Diff
#414 Extend util by hashFromFile
parent
cd912069
No related branches found
No related tags found
2 merge requests
!2
#414 Remaining changes from MR
,
!1
planning#414 Methoden Signaturen (Zwischenstand)
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
impl/src/main/java/de/fitko/fitconnect/impl/crypto/HashUtil.java
+17
-3
17 additions, 3 deletions
...c/main/java/de/fitko/fitconnect/impl/crypto/HashUtil.java
impl/src/test/java/fitconnect/impl/crypto/HashUtilTest.java
+4
-4
4 additions, 4 deletions
impl/src/test/java/fitconnect/impl/crypto/HashUtilTest.java
with
21 additions
and
7 deletions
impl/src/main/java/de/fitko/fitconnect/impl/crypto/
MetadataVerifier
.java
→
impl/src/main/java/de/fitko/fitconnect/impl/crypto/
HashUtil
.java
+
17
−
3
View file @
5a691ec3
...
@@ -2,16 +2,20 @@ package de.fitko.fitconnect.impl.crypto;
...
@@ -2,16 +2,20 @@ package de.fitko.fitconnect.impl.crypto;
import
de.fitko.fitconnect.api.exceptions.internal.InitializationException
;
import
de.fitko.fitconnect.api.exceptions.internal.InitializationException
;
import
java.io.File
;
import
java.io.IOException
;
import
java.nio.file.Files
;
import
java.nio.file.Paths
;
import
java.security.MessageDigest
;
import
java.security.MessageDigest
;
import
java.security.NoSuchAlgorithmException
;
import
java.security.NoSuchAlgorithmException
;
public
class
MetadataVerifier
{
public
class
HashUtil
{
private
static
final
String
DEFAULT_ALGORITHM
=
"SHA-512"
;
// Currently, only SHA-512 is supported.
private
static
final
String
DEFAULT_ALGORITHM
=
"SHA-512"
;
// Currently, only SHA-512 is supported.
private
final
MessageDigest
messageDigest
;
private
final
MessageDigest
messageDigest
;
public
MetadataVerifier
()
{
public
HashUtil
()
{
try
{
try
{
this
.
messageDigest
=
MessageDigest
.
getInstance
(
DEFAULT_ALGORITHM
);
this
.
messageDigest
=
MessageDigest
.
getInstance
(
DEFAULT_ALGORITHM
);
}
catch
(
NoSuchAlgorithmException
e
)
{
}
catch
(
NoSuchAlgorithmException
e
)
{
...
@@ -19,7 +23,7 @@ public class MetadataVerifier {
...
@@ -19,7 +23,7 @@ public class MetadataVerifier {
}
}
}
}
public
MetadataVerifier
(
final
MessageDigest
messageDigest
)
{
public
HashUtil
(
final
MessageDigest
messageDigest
)
{
this
.
messageDigest
=
messageDigest
;
this
.
messageDigest
=
messageDigest
;
}
}
...
@@ -33,6 +37,15 @@ public class MetadataVerifier {
...
@@ -33,6 +37,15 @@ public class MetadataVerifier {
return
compareHashes
(
originalHash
,
newHash
);
return
compareHashes
(
originalHash
,
newHash
);
}
}
public
String
createHashFromFile
(
File
file
)
throws
IOException
{
try
{
byte
[]
rawData
=
Files
.
readAllBytes
(
Paths
.
get
(
file
.
getPath
()));
return
new
String
(
rawData
);
}
catch
(
IOException
e
)
{
throw
e
;
}
}
private
boolean
compareHashes
(
byte
[]
originalHash
,
byte
[]
comparisonHash
)
{
private
boolean
compareHashes
(
byte
[]
originalHash
,
byte
[]
comparisonHash
)
{
int
diff
=
originalHash
.
length
^
comparisonHash
.
length
;
int
diff
=
originalHash
.
length
^
comparisonHash
.
length
;
for
(
int
i
=
0
;
i
<
originalHash
.
length
&&
i
<
comparisonHash
.
length
;
i
++)
{
for
(
int
i
=
0
;
i
<
originalHash
.
length
&&
i
<
comparisonHash
.
length
;
i
++)
{
...
@@ -40,4 +53,5 @@ public class MetadataVerifier {
...
@@ -40,4 +53,5 @@ public class MetadataVerifier {
}
}
return
diff
==
0
;
return
diff
==
0
;
}
}
}
}
This diff is collapsed.
Click to expand it.
impl/src/test/java/fitconnect/impl/crypto/
MetadataVerifier
Test.java
→
impl/src/test/java/fitconnect/impl/crypto/
HashUtil
Test.java
+
4
−
4
View file @
5a691ec3
package
fitconnect.impl.crypto
;
package
fitconnect.impl.crypto
;
import
de.fitko.fitconnect.impl.crypto.
MetadataVerifier
;
import
de.fitko.fitconnect.impl.crypto.
HashUtil
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
java.io.IOException
;
import
java.io.IOException
;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.*;
import
static
org
.
junit
.
jupiter
.
api
.
Assertions
.*;
class
MetadataVerifier
Test
{
class
HashUtil
Test
{
MetadataVerifier
underTest
=
new
MetadataVerifier
();
HashUtil
underTest
=
new
HashUtil
();
@Test
@Test
public
void
testMessageDigestForDataAndAttachments
()
throws
IOException
{
public
void
testMessageDigestForDataAndAttachments
()
throws
IOException
{
...
@@ -24,7 +24,7 @@ class MetadataVerifierTest {
...
@@ -24,7 +24,7 @@ class MetadataVerifierTest {
}
}
private
byte
[]
getExampleFileContent
(
final
String
path
)
throws
IOException
{
private
byte
[]
getExampleFileContent
(
final
String
path
)
throws
IOException
{
return
MetadataVerifier
.
class
.
getResourceAsStream
(
path
).
readAllBytes
();
return
HashUtil
.
class
.
getResourceAsStream
(
path
).
readAllBytes
();
}
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment