Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
FallIntoOblivion
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Pedro Cavaleiro
FallIntoOblivion
Commits
7a80299d
Commit
7a80299d
authored
Dec 01, 2017
by
Pedro Cavaleiro
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Organized file handling functions into one class
Helpers.FileHelpers
parent
b4bd2191
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
70 additions
and
53 deletions
+70
-53
FallIntoOblivion.java
FallIntoOblivion/src/fallintooblivion/FallIntoOblivion.java
+14
-29
Helpers.java
FallIntoOblivion/src/fallintooblivion/Helpers.java
+56
-1
Ler.java
FallIntoOblivion/src/fallintooblivion/Ler.java
+0
-23
No files found.
FallIntoOblivion/src/fallintooblivion/FallIntoOblivion.java
View file @
7a80299d
...
@@ -25,7 +25,7 @@ public class FallIntoOblivion {
...
@@ -25,7 +25,7 @@ public class FallIntoOblivion {
private
static
Configs
conf
=
new
Configs
();
private
static
Configs
conf
=
new
Configs
();
private
static
ReentrantLock
propertiesLock
=
new
ReentrantLock
();
private
static
ReentrantLock
propertiesLock
=
new
ReentrantLock
();
private
static
final
String
availableCommands
=
"Available commands: setcypher set
validation set
hash setenabled showconfig\n"
;
private
static
final
String
availableCommands
=
"Available commands: setcypher sethash setenabled showconfig\n"
;
private
static
final
String
setCypherCommandString
=
"setcypher [cyphertype] [keysize]\nCypher Types:\naes_cbc\n"
;
private
static
final
String
setCypherCommandString
=
"setcypher [cyphertype] [keysize]\nCypher Types:\naes_cbc\n"
;
private
static
final
String
setFileValidationCommandString
=
"setvalidation [validationmethod]\nAvailable Methods:\nhash\ndigital_signature\n"
;
private
static
final
String
setFileValidationCommandString
=
"setvalidation [validationmethod]\nAvailable Methods:\nhash\ndigital_signature\n"
;
...
@@ -63,15 +63,15 @@ public class FallIntoOblivion {
...
@@ -63,15 +63,15 @@ public class FallIntoOblivion {
try
{
try
{
Dir
.
mkdir
();
Dir
.
mkdir
();
result
=
true
;
result
=
true
;
}
}
catch
(
SecurityException
se
){
catch
(
SecurityException
se
){
System
.
out
.
println
(
"Something went wrong with creating your new very useless trash folder"
);
System
.
out
.
println
(
"Something went wrong with creating your new very useless trash folder"
);
}
}
if
(
result
)
{
if
(
result
)
{
System
.
out
.
println
(
"DIR created"
);
System
.
out
.
println
(
"DIR created"
);
}
}
}
}
//Test if FallIntoOblivion has a trashed folder if not create it
//Test if FallIntoOblivion has a trashed folder if not create it
File
TrashDir
=
new
File
(
Dir
.
getName
()
+
"/Trashed"
);
File
TrashDir
=
new
File
(
Dir
.
getName
()
+
"/Trashed"
);
if
(!
TrashDir
.
exists
())
{
if
(!
TrashDir
.
exists
())
{
...
@@ -80,11 +80,11 @@ public class FallIntoOblivion {
...
@@ -80,11 +80,11 @@ public class FallIntoOblivion {
try
{
try
{
TrashDir
.
mkdir
();
TrashDir
.
mkdir
();
result
=
true
;
result
=
true
;
}
}
catch
(
SecurityException
se
){
catch
(
SecurityException
se
){
System
.
out
.
println
(
"You shouln't delete your Trashed folder"
);
System
.
out
.
println
(
"You shouln't delete your Trashed folder"
);
}
}
if
(
result
)
{
if
(
result
)
{
System
.
out
.
println
(
"Trashed DIR created"
);
System
.
out
.
println
(
"Trashed DIR created"
);
}
}
}
}
...
@@ -143,12 +143,12 @@ public class FallIntoOblivion {
...
@@ -143,12 +143,12 @@ public class FallIntoOblivion {
}
catch
(
Exception
ex
)
{
}
catch
(
Exception
ex
)
{
System
.
out
.
println
(
ex
);
System
.
out
.
println
(
ex
);
}
}
deleteDirectory
(
file
);
Helpers
.
FileHelpers
.
deleteDirectory
(
file
);
WatchDir
.
foldersToEncrypt
.
remove
(
file
);
WatchDir
.
foldersToEncrypt
.
remove
(
file
);
file
=
new
File
(
file
.
getAbsolutePath
()
+
".zip"
);
file
=
new
File
(
file
.
getAbsolutePath
()
+
".zip"
);
}
}
byte
[]
fBytes
=
Ler
.
umFicheiro
(
file
.
getAbsolutePath
());
byte
[]
fBytes
=
Helpers
.
FileHelpers
.
umFicheiro
(
file
.
getAbsolutePath
());
File
folder
=
new
File
(
"Fall_Into_Oblivion/Trashed/"
+
file
.
getName
());
File
folder
=
new
File
(
"Fall_Into_Oblivion/Trashed/"
+
file
.
getName
());
if
(!
folder
.
exists
())
{
if
(!
folder
.
exists
())
{
...
@@ -162,7 +162,7 @@ public class FallIntoOblivion {
...
@@ -162,7 +162,7 @@ public class FallIntoOblivion {
String
zeroHASH
=
SHA256
.
calculateStringMAC
(
"0000"
);
String
zeroHASH
=
SHA256
.
calculateStringMAC
(
"0000"
);
System
.
out
.
println
(
zeroHASH
.
subSequence
(
0
,
16
).
toString
());
System
.
out
.
println
(
zeroHASH
.
subSequence
(
0
,
16
).
toString
());
byte
[]
encBytes
=
AES_CBC
.
encrypt
(
zeroHASH
.
subSequence
(
0
,
16
).
toString
(),
"0000000000000000"
,
fBytes
);
byte
[]
encBytes
=
AES_CBC
.
encrypt
(
zeroHASH
.
subSequence
(
0
,
16
).
toString
(),
"0000000000000000"
,
fBytes
);
Ler
.
escreverFicheiro
(
"Fall_Into_Oblivion/Trashed/"
+
file
.
getName
()
+
"/"
+
file
.
getName
(),
cyphertype
.
replaceAll
(
"_"
,
""
),
encBytes
);
Helpers
.
FileHelpers
.
escreverFicheiro
(
"Fall_Into_Oblivion/Trashed/"
+
file
.
getName
()
+
"/"
+
file
.
getName
(),
cyphertype
.
replaceAll
(
"_"
,
""
),
encBytes
);
encryptedFolders
.
add
(
folder
.
toString
());
encryptedFolders
.
add
(
folder
.
toString
());
file
.
delete
();
file
.
delete
();
WatchDir
.
foldersToEncrypt
.
remove
(
f
);
WatchDir
.
foldersToEncrypt
.
remove
(
f
);
...
@@ -305,6 +305,7 @@ public class FallIntoOblivion {
...
@@ -305,6 +305,7 @@ public class FallIntoOblivion {
/**
/**
* Define qual o método pelo qual vai ser verificada a integridade dos ficheiros
* Define qual o método pelo qual vai ser verificada a integridade dos ficheiros
* Disponiveis atualmente HASH e Assinatura Digital
* Disponiveis atualmente HASH e Assinatura Digital
* Atualmente só será usada Assinatura digital
* @param words um array de strings que contem os comandos necessários
* @param words um array de strings que contem os comandos necessários
*/
*/
private
static
void
setFileValidationMethod
(
String
[]
words
)
{
private
static
void
setFileValidationMethod
(
String
[]
words
)
{
...
@@ -364,6 +365,7 @@ public class FallIntoOblivion {
...
@@ -364,6 +365,7 @@ public class FallIntoOblivion {
System
.
out
.
println
(
"setEnabled [boolean]\n"
);
//add new types here too
System
.
out
.
println
(
"setEnabled [boolean]\n"
);
//add new types here too
}
}
}
}
public
static
String
listToString
(
ArrayList
<
String
>
list
)
{
public
static
String
listToString
(
ArrayList
<
String
>
list
)
{
String
result
=
""
;
String
result
=
""
;
...
@@ -375,21 +377,4 @@ public class FallIntoOblivion {
...
@@ -375,21 +377,4 @@ public class FallIntoOblivion {
}
}
return
result
;
return
result
;
}
}
public
static
boolean
deleteDirectory
(
File
directory
)
{
if
(
directory
.
exists
()){
File
[]
files
=
directory
.
listFiles
();
if
(
null
!=
files
){
for
(
int
i
=
0
;
i
<
files
.
length
;
i
++)
{
if
(
files
[
i
].
isDirectory
())
{
deleteDirectory
(
files
[
i
]);
}
else
{
files
[
i
].
delete
();
}
}
}
}
return
(
directory
.
delete
());
}
}
}
FallIntoOblivion/src/fallintooblivion/Helpers.java
View file @
7a80299d
...
@@ -5,6 +5,10 @@
...
@@ -5,6 +5,10 @@
*/
*/
package
fallintooblivion
;
package
fallintooblivion
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileOutputStream
;
/**
/**
*
*
* @author pedrocavaleiro
* @author pedrocavaleiro
...
@@ -12,7 +16,58 @@ package fallintooblivion;
...
@@ -12,7 +16,58 @@ package fallintooblivion;
public
class
Helpers
{
public
class
Helpers
{
public
static
class
FileHelpers
{
public
static
class
FileHelpers
{
/**
* Apaga um diretório recursivamente
* @param directory diretório a ser apagado
* @return verdadeiro se foi apagado caso contrario falso
*/
public
static
boolean
deleteDirectory
(
File
directory
)
{
if
(
directory
.
exists
()){
File
[]
files
=
directory
.
listFiles
();
if
(
null
!=
files
){
for
(
int
i
=
0
;
i
<
files
.
length
;
i
++)
{
if
(
files
[
i
].
isDirectory
())
{
deleteDirectory
(
files
[
i
]);
}
else
{
files
[
i
].
delete
();
}
}
}
}
return
(
directory
.
delete
());
}
/**
* Lê um ficheiro inteiro para a memoria. Não recomendado para ficheiros
* grandes
* @param filePath caminho completo para o ficheiro
* @return devolve os bytes do ficheiro
* @throws Exception
*/
public
static
byte
[]
umFicheiro
(
String
filePath
)
throws
Exception
{
File
file
=
new
File
(
filePath
);
byte
[]
getBytes
=
new
byte
[(
int
)
file
.
length
()];
FileInputStream
fsIn
=
new
FileInputStream
(
file
);
fsIn
.
read
(
getBytes
);
fsIn
.
close
();
return
getBytes
;
}
/**
* Escreve um ficheiro para o disco.
* @param filepath Ficheiro onde serão escritos os bytes
* @param extension Extensão do ficheiro
* @param bytes Bytes para serem escritos
* @throws Exception Excepção generica
*/
public
static
void
escreverFicheiro
(
String
filepath
,
String
extension
,
byte
[]
bytes
)
throws
Exception
{
FileOutputStream
fsOut
=
new
FileOutputStream
(
filepath
+
"."
+
extension
);
fsOut
.
write
(
bytes
);
fsOut
.
close
();
}
}
}
}
}
FallIntoOblivion/src/fallintooblivion/Ler.java
View file @
7a80299d
...
@@ -50,27 +50,4 @@ public class Ler{
...
@@ -50,27 +50,4 @@ public class Ler{
}
}
}
}
}
}
/**
* Lê um ficheiro inteiro para a memoria. Não recomendado para ficheiros
* grandes
* @param filePath caminho completo para o ficheiro
* @return devolve os bytes do ficheiro
* @throws Exception
*/
public
static
byte
[]
umFicheiro
(
String
filePath
)
throws
Exception
{
File
file
=
new
File
(
filePath
);
byte
[]
getBytes
=
new
byte
[(
int
)
file
.
length
()];
FileInputStream
fsIn
=
new
FileInputStream
(
file
);
fsIn
.
read
(
getBytes
);
fsIn
.
close
();
return
getBytes
;
}
public
static
void
escreverFicheiro
(
String
filepath
,
String
extension
,
byte
[]
bytes
)
throws
Exception
{
FileOutputStream
fsOut
=
new
FileOutputStream
(
filepath
+
"."
+
extension
);
fsOut
.
write
(
bytes
);
fsOut
.
close
();
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment