-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
40 additions
and
9 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,28 @@ | ||
package org.cryptomator.cryptofs; | ||
|
||
import com.google.common.io.BaseEncoding; | ||
|
||
import java.security.MessageDigest; | ||
import java.security.NoSuchAlgorithmException; | ||
|
||
/** | ||
* Utility class for generating a suffix for the backup file to make it unique to its original master key file. | ||
*/ | ||
public class BackupUtil { | ||
|
||
/** | ||
* Computes the SHA-256 digest of the given byte array and returns a file suffix containing the first 4 bytes in hex string format. | ||
* | ||
* @param fileBytes the input byte for which the digest is computed | ||
* @return "." + first 4 bytes of SHA-256 digest in hex string format | ||
*/ | ||
public static String generateFileIdSuffix(byte[] fileBytes) { | ||
try { | ||
MessageDigest md = MessageDigest.getInstance("SHA-256"); | ||
byte[] digest = md.digest(fileBytes); | ||
return "." + BaseEncoding.base16().encode(digest, 0, 4); | ||
} catch (NoSuchAlgorithmException e) { | ||
throw new IllegalStateException("Every Java Platform must support the Message Digest algorithm SHA-256", e); | ||
} | ||
} | ||
} |
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
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
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