Correction FileSize Système de hashage Sha256 et ajout précision sur nom de l'interface si celle-ci n'est pas trouvée (net chooser).

This commit is contained in:
Jérémi N ‘EndMove’ 2022-03-15 13:49:31 +01:00
parent 1a91271324
commit 031ac57368
Signed by: EndMove
GPG Key ID: 65C4A02E1F5371A4
5 changed files with 15 additions and 17 deletions

View File

@ -20,7 +20,6 @@ import java.nio.file.Paths;
public class App {
public static void main(String[] args) {
setupVM();
Repository repositoryStorage = prepareStorage();
@ -37,18 +36,10 @@ public class App {
FileFrontEnd ffe = new FileFrontEnd(clientRep, storeRep, protocolRep);
new UnicastServerListener(ffe, clientRep, protocolRep, repositoryStorage, repositoryStorage.getUnicastPort());
new MulticastServerListener(ffe, storeRep, protocolRep, repositoryStorage.getMulticastIp(), repositoryStorage.getMulticastPort(), repositoryStorage.getNetworkInterface());
// close repo et client et server.
// Thread.sleep(60000);
// clientRep.close();
// storeRep.close();
}
private static void initProtocols(Repository repositoryStorage, ProtocolRepository protocolRep) {
initReadersProtocols(repositoryStorage, protocolRep);
initWritersProtocols(repositoryStorage, protocolRep);
}

View File

@ -4,7 +4,6 @@ import org.mindrot.jbcrypt.BCrypt;
public class BCryptHasher {
public static String hashPassword(String plainTextPassword) {
return BCrypt.hashpw(plainTextPassword, BCrypt.gensalt());
}

View File

@ -59,7 +59,7 @@ public class NetChooser {
if(interfaces.size() > 0) {
String[] result = new String[interfaces.size()];
for (int i = 0; i < interfaces.size(); ++i) {
result[i] = interfaces.get(i).getDisplayName();
result[i] = interfaces.get(i).getDisplayName() + " --> " + interfaces.get(i).getName();
}
return result;
} else

View File

@ -27,10 +27,10 @@ public class SHA {
/*
* BORROWING ENCRYPTION DEMO
*/
File inFile = new File("D:\\HELMo.txt");
File inFile = new File("D:\\HELMoCrypted.png");
System.out.println(hashStream(
new FileInputStream(inFile),
(int)inFile.length()
inFile.length()
));
System.out.println(hashFile( // caca5439dc02f2ced5094e95f1a3403d42127cda29feecd2eb1c68ff38a6fee3
@ -44,12 +44,12 @@ public class SHA {
*
* @param in InputStream to the input, flux to hash.
* @param fileSize Stream/file size.
*ichier, utilisé
*
* @return Borrowing of the full current flux.
*
* @throws ShaException if an error occur.
*/
public static String hashStream(InputStream in, int fileSize) throws ShaException {
public static String hashStream(InputStream in, long fileSize) throws ShaException {
StringBuilder sb = new StringBuilder();
byte[] buffer = new byte[1024];
int currentSize = 0;
@ -87,7 +87,7 @@ public class SHA {
public static String hashFile(String rootPath, String fileName) throws ShaException {
try {
File file = new File(String.format("%s/%s", rootPath, fileName));
return hashStream(new FileInputStream(file), (int)file.length());
return hashStream(new FileInputStream(file), file.length());
} catch (Exception e) {
throw new ShaException(e);
}

View File

@ -1 +1,9 @@
{"unicast_port":8000,"multicast_ip":"224.66.66.1","multicast_port":15502,"network_interface":"","tls":true,"storagePath":"/home/benjamin/ffe","users":[{"name":"aaaaa","password":"$2a$10$nDCEDVwbNO/YDQ4qdRcxfuES4.aboluLzWouXXsk6vDoaWocv516W","aes_key":"kYtwHy9qJBg30WS6axWTFGVE0Ge5kpYiJJlC+COIEI4=","files":[]}]}
{
"unicast_port": 8000,
"multicast_ip": "224.66.66.1",
"multicast_port": 15502,
"network_interface": "lo",
"tls": true,
"storagePath": "D:\\ffe",
"users": []
}