Toggle navigation
Toggle navigation
This project
Loading...
Sign in
2020-1-capstone-design2
/
2013104053
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
김동준
2020-06-11 19:59:12 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
042085fc69681073d7f0f10ff934f16bd361d2a0
042085fc
1 parent
3b3aebdf
Implementation completed
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
504 additions
and
67 deletions
DLPonUSB/src/cryptor/DecryptWindow.java
DLPonUSB/src/cryptor/DeleteEncypted.java
DLPonUSB/src/cryptor/EncryptWindow.java
DLPonUSB/src/cryptor/LogWindow.java
DLPonUSB/src/cryptor/MainMenu.java
DLPonUSB/src/cryptor/SignIn.java
DLPonUSB/src/cryptor/SignUp.java
DLPonUSB/src/cryptor/DecryptWindow.java
View file @
042085f
...
...
@@ -48,6 +48,11 @@ class DecryptWindow extends Frame {
String
folderDir
=
".\\"
+
userId
+
"\\Encrypted"
;
final
File
dirToLock
=
new
File
(
folderDir
);
if
(!
dirToLock
.
exists
())
{
JOptionPane
.
showMessageDialog
(
null
,
"No files have been encrypted!"
);
return
;
}
JFileChooser
jfc
=
new
JFileChooser
(
dirToLock
);
jfc
.
setFileView
(
new
FileView
()
{
@Override
...
...
@@ -62,7 +67,7 @@ class DecryptWindow extends Frame {
lpwd
=
new
Label
(
"Enter password: "
,
Label
.
RIGHT
);
lmod
=
new
Label
(
"
열람 목적
: "
,
Label
.
RIGHT
);
lmod
=
new
Label
(
"
Enter purpose
: "
,
Label
.
RIGHT
);
//약 10개의 글자를 입력할 수 있는 TextField 생성.
...
...
@@ -71,7 +76,7 @@ class DecryptWindow extends Frame {
tfMod
=
new
TextField
(
10
);
//입력한 값 대신 '*'이 보이게 한다.
tfPwd
.
setEchoChar
(
'*'
);
ok
=
new
Button
(
"OK"
);
...
...
@@ -102,7 +107,9 @@ class DecryptWindow extends Frame {
add
(
ok
);
setSize
(
450
,
65
);
setSize
(
450
,
100
);
this
.
setLocationRelativeTo
(
null
);
//화면이 보이게 한다.
...
...
@@ -126,6 +133,12 @@ class DecryptWindow extends Frame {
dispose
();
if
(
tfMod
.
getText
().
length
()
<
1
)
{
JOptionPane
.
showMessageDialog
(
null
,
"Purpose cannot be null."
);
return
;
}
String
passwd
=
userId
+
' '
+
tfPwd
.
getText
();
char
[]
password
=
passwd
.
toCharArray
();
String
passwd2
=
userId
+
' '
+
userPW
;
...
...
@@ -151,7 +164,11 @@ class DecryptWindow extends Frame {
}
catch
(
IOException
ioException
)
{
ioException
.
printStackTrace
();
}
catch
(
GeneralSecurityException
generalSecurityException
)
{
generalSecurityException
.
printStackTrace
();
String
tempdir
=
".\\"
+
userId
+
"\\logs\\"
+
fileName
+
".txt"
;
File
temp
=
new
File
(
tempdir
);
temp
.
delete
();
JOptionPane
.
showMessageDialog
(
null
,
"Password is invalid!"
);
return
;
}
dir
=
".\\"
+
userId
+
"\\logs\\"
+
fileName
+
".txt"
;
...
...
@@ -175,7 +192,7 @@ class DecryptWindow extends Frame {
Date
time
=
new
Date
();
String
time1
=
format1
.
format
(
time
);
String
toWrite
=
"
열람
\t"
+
time1
+
'\t'
+
modeIn
+
'\n'
;
String
toWrite
=
"
OPN
\t"
+
time1
+
'\t'
+
modeIn
+
'\n'
;
byte
[]
b
=
toWrite
.
getBytes
();
try
{
fos
.
write
(
b
);
...
...
DLPonUSB/src/cryptor/DeleteEncypted.java
View file @
042085f
...
...
@@ -6,8 +6,12 @@ import java.awt.*;
import
java.awt.event.ActionEvent
;
import
java.awt.event.ActionListener
;
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.security.GeneralSecurityException
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
class
DeleteEncypted
extends
Frame
{
...
...
@@ -33,6 +37,11 @@ class DeleteEncypted extends Frame {
String
folderDir
=
".\\"
+
userId
+
"\\Encrypted"
;
final
File
dirToLock
=
new
File
(
folderDir
);
if
(!
dirToLock
.
exists
())
{
JOptionPane
.
showMessageDialog
(
null
,
"No files have been encrypted!"
);
return
;
}
JFileChooser
jfc
=
new
JFileChooser
(
dirToLock
);
jfc
.
setFileView
(
new
FileView
()
{
@Override
...
...
@@ -48,7 +57,61 @@ class DeleteEncypted extends Frame {
if
(
file
.
exists
())
{
file
.
deleteOnExit
();
String
fileName
=
file
.
getName
();
String
passwd2
=
userId
+
' '
+
userPW
;
char
[]
password2
=
passwd2
.
toCharArray
();
String
dir
=
".\\"
+
userId
+
"\\logs\\"
+
fileName
+
".txt"
;
String
dir2
=
".\\"
+
userId
+
"\\logs\\"
+
fileName
+
".log"
;
try
{
Cryptor
.
decrypt
(
dir2
,
dir
,
password2
);
}
catch
(
IOException
ioException
)
{
ioException
.
printStackTrace
();
}
catch
(
GeneralSecurityException
generalSecurityException
)
{
generalSecurityException
.
printStackTrace
();
}
FileOutputStream
fos
=
null
;
try
{
fos
=
new
FileOutputStream
(
dir
,
true
);
}
catch
(
FileNotFoundException
fileNotFoundException
)
{
fileNotFoundException
.
printStackTrace
();
}
SimpleDateFormat
format1
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm"
);
Date
time
=
new
Date
();
String
time1
=
format1
.
format
(
time
);
String
toWrite
=
"DEL\t"
+
time1
+
'\t'
+
"Finished using File"
+
'\n'
;
byte
[]
b
=
toWrite
.
getBytes
();
try
{
fos
.
write
(
b
);
}
catch
(
IOException
ioException
)
{
ioException
.
printStackTrace
();
}
try
{
fos
.
flush
();
}
catch
(
IOException
ioException
)
{
ioException
.
printStackTrace
();
}
try
{
fos
.
close
();
}
catch
(
IOException
ioException
)
{
ioException
.
printStackTrace
();
}
try
{
Cryptor
.
encrypt
(
dir
,
dir2
,
password2
);
}
catch
(
IOException
ioException
)
{
ioException
.
printStackTrace
();
}
catch
(
GeneralSecurityException
generalSecurityException
)
{
generalSecurityException
.
printStackTrace
();
}
File
temp
=
new
File
(
dir
);
temp
.
delete
();
file
.
delete
();
}
}
...
...
DLPonUSB/src/cryptor/EncryptWindow.java
View file @
042085f
...
...
@@ -51,7 +51,7 @@ class EncryptWindow extends Frame {
lpwd
=
new
Label
(
"Enter password: "
,
Label
.
RIGHT
);
lmod
=
new
Label
(
"
사용 목적
: "
,
Label
.
RIGHT
);
lmod
=
new
Label
(
"
Enter purpose
: "
,
Label
.
RIGHT
);
//약 10개의 글자를 입력할 수 있는 TextField 생성.
...
...
@@ -60,7 +60,7 @@ class EncryptWindow extends Frame {
tfMod
=
new
TextField
(
10
);
//입력한 값 대신 '*'이 보이게 한다.
tfPwd
.
setEchoChar
(
'*'
);
ok
=
new
Button
(
"OK"
);
...
...
@@ -90,7 +90,9 @@ class EncryptWindow extends Frame {
add
(
ok
);
setSize
(
450
,
65
);
setSize
(
450
,
100
);
this
.
setLocationRelativeTo
(
null
);
//화면이 보이게 한다.
...
...
@@ -112,6 +114,12 @@ class EncryptWindow extends Frame {
dispose
();
if
(
tfPwd
.
getText
().
length
()
<
1
||
tfMod
.
getText
().
length
()
<
1
)
{
JOptionPane
.
showMessageDialog
(
null
,
"Password and purpose cannot be null."
);
return
;
}
String
passwd
=
userId
+
' '
+
tfPwd
.
getText
();
char
[]
password
=
passwd
.
toCharArray
();
String
passwd2
=
userId
+
' '
+
userPW
;
...
...
@@ -166,7 +174,7 @@ class EncryptWindow extends Frame {
Date
time
=
new
Date
();
String
time1
=
format1
.
format
(
time
);
String
toWrite
=
"
등록
\t"
+
time1
+
'\t'
+
modeIn
+
'\n'
;
String
toWrite
=
"
REG
\t"
+
time1
+
'\t'
+
modeIn
+
'\n'
;
byte
[]
b
=
toWrite
.
getBytes
();
try
{
fos
.
write
(
b
);
...
...
DLPonUSB/src/cryptor/LogWindow.java
View file @
042085f
...
...
@@ -37,6 +37,11 @@ class LogWindow extends Frame {
String
folderDir
=
".\\"
+
userId
+
"\\logs"
;
final
File
dirToLock
=
new
File
(
folderDir
);
if
(!
dirToLock
.
exists
())
{
JOptionPane
.
showMessageDialog
(
null
,
"No files have been encrypted!"
);
return
;
}
JFileChooser
jfc
=
new
JFileChooser
(
dirToLock
);
jfc
.
setFileView
(
new
FileView
()
{
@Override
...
...
@@ -83,7 +88,7 @@ class LogWindow extends Frame {
}
catch
(
InterruptedException
interruptedException
)
{
interruptedException
.
printStackTrace
();
}
file
.
delete
OnExit
();
file
.
delete
();
}
public
static
void
main
(
String
args
[]){
...
...
DLPonUSB/src/cryptor/MainMenu.java
View file @
042085f
...
...
@@ -70,7 +70,7 @@ class MainMenu extends Frame {
//LayoutManager를 FlowLayout으로
setLayout
(
new
FlowLayout
(
));
setLayout
(
new
GridLayout
(
4
,
1
));
//생성한 component들을 Frame에 포함시킨다.
...
...
@@ -82,7 +82,9 @@ class MainMenu extends Frame {
add
(
bDelete
);
setSize
(
450
,
200
);
setSize
(
450
,
400
);
this
.
setLocationRelativeTo
(
null
);
//화면이 보이게 한다.
...
...
@@ -102,60 +104,6 @@ class MainMenu extends Frame {
if
(
file
.
isDirectory
())
{
deleteDirectory
(
file
,
userId
,
userPW
);
}
else
{
String
fileName
=
file
.
getName
();
String
passwd2
=
userId
+
' '
+
userPW
;
char
[]
password2
=
passwd2
.
toCharArray
();
String
dir
=
".\\"
+
userId
+
"\\logs\\"
+
fileName
+
".txt"
;
String
dir2
=
".\\"
+
userId
+
"\\logs\\"
+
fileName
+
".log"
;
try
{
Cryptor
.
decrypt
(
dir2
,
dir
,
password2
);
}
catch
(
IOException
ioException
)
{
ioException
.
printStackTrace
();
}
catch
(
GeneralSecurityException
generalSecurityException
)
{
generalSecurityException
.
printStackTrace
();
}
FileOutputStream
fos
=
null
;
try
{
fos
=
new
FileOutputStream
(
dir
,
true
);
}
catch
(
FileNotFoundException
fileNotFoundException
)
{
fileNotFoundException
.
printStackTrace
();
}
SimpleDateFormat
format1
=
new
SimpleDateFormat
(
"yyyy-MM-dd HH:mm"
);
Date
time
=
new
Date
();
String
time1
=
format1
.
format
(
time
);
String
toWrite
=
"삭제\t"
+
time1
+
'\t'
+
"사용 완료"
+
'\n'
;
byte
[]
b
=
toWrite
.
getBytes
();
try
{
fos
.
write
(
b
);
}
catch
(
IOException
ioException
)
{
ioException
.
printStackTrace
();
}
try
{
fos
.
flush
();
}
catch
(
IOException
ioException
)
{
ioException
.
printStackTrace
();
}
try
{
fos
.
close
();
}
catch
(
IOException
ioException
)
{
ioException
.
printStackTrace
();
}
try
{
Cryptor
.
encrypt
(
dir
,
dir2
,
password2
);
}
catch
(
IOException
ioException
)
{
ioException
.
printStackTrace
();
}
catch
(
GeneralSecurityException
generalSecurityException
)
{
generalSecurityException
.
printStackTrace
();
}
File
temp
=
new
File
(
dir
);
temp
.
delete
();
file
.
delete
();
}
}
...
...
DLPonUSB/src/cryptor/SignIn.java
0 → 100644
View file @
042085f
package
cryptor
;
import
javax.annotation.processing.Filer
;
import
javax.swing.*
;
import
java.awt.*
;
import
java.awt.event.ActionEvent
;
import
java.awt.event.ActionListener
;
import
java.awt.event.WindowAdapter
;
import
java.awt.event.WindowEvent
;
import
java.io.*
;
import
java.security.GeneralSecurityException
;
import
java.security.MessageDigest
;
import
java.security.NoSuchAlgorithmException
;
class
SignIn
extends
Frame
{
Label
lid
;
Label
lpwd
;
TextField
tfId
;
TextField
tfPwd
;
Button
ok
;
Button
su
;
SignIn
(
String
title
){
//Frame(String title)을 호출한다.
super
(
title
);
addWindowListener
(
new
WindowAdapter
()
{
@Override
public
void
windowClosing
(
WindowEvent
e
)
{
dispose
();
System
.
exit
(
0
);
}
});
//Label의 text정렬을 오른쪽으로
lid
=
new
Label
(
"ID : "
,
Label
.
RIGHT
);
lpwd
=
new
Label
(
"Password : "
,
Label
.
RIGHT
);
//약 10개의 글자를 입력할 수 있는 TextField 생성.
tfId
=
new
TextField
(
10
);
tfPwd
=
new
TextField
(
10
);
//입력한 값 대신 '*'이 보이게 한다.
tfPwd
.
setEchoChar
(
'*'
);
ok
=
new
Button
(
"OK"
);
su
=
new
Button
(
"Sign Up"
);
//OK버튼과 TextField에 이벤트처리를 위한 Listener를 추가해준다.
tfId
.
addActionListener
(
new
EventHandler
());
tfPwd
.
addActionListener
(
new
EventHandler
());
ok
.
addActionListener
(
new
EventHandler
());
su
.
addActionListener
(
e
->
{
SignUp
f
=
new
SignUp
(
"Sign Up"
);
});
//LayoutManager를 FlowLayout으로
setLayout
(
new
FlowLayout
());
//생성한 component들을 Frame에 포함시킨다.
add
(
lid
);
add
(
tfId
);
add
(
lpwd
);
add
(
tfPwd
);
add
(
ok
);
add
(
su
);
setSize
(
450
,
80
);
this
.
setLocationRelativeTo
(
null
);
//화면이 보이게 한다.
setVisible
(
true
);
}
public
static
void
main
(
String
args
[]){
SignIn
f
=
new
SignIn
(
"Sign In"
);
}
class
EventHandler
implements
ActionListener
{
public
void
actionPerformed
(
ActionEvent
e
){
String
passwd
=
tfId
.
getText
()
+
' '
+
tfPwd
.
getText
();
char
[]
password
=
passwd
.
toCharArray
();
String
dir
=
".\\Users\\"
+
tfId
.
getText
()
+
".txt"
;
String
dir2
=
".\\Users\\"
+
tfId
.
getText
()
+
".info"
;
File
f
=
new
File
(
dir2
);
if
(
f
.
exists
())
{
try
{
Cryptor
.
decrypt
(
dir2
,
dir
,
password
);
}
catch
(
IOException
ioException
)
{
ioException
.
printStackTrace
();
}
catch
(
GeneralSecurityException
generalSecurityException
)
{
JOptionPane
.
showMessageDialog
(
null
,
"Password is invalid!"
);
return
;
}
dispose
();
File
file
=
new
File
(
dir
);
FileReader
fr
=
null
;
try
{
fr
=
new
FileReader
(
file
);
}
catch
(
FileNotFoundException
fileNotFoundException
)
{
fileNotFoundException
.
printStackTrace
();
}
BufferedReader
bufReader
=
new
BufferedReader
(
fr
);
String
line
=
""
;
try
{
line
=
bufReader
.
readLine
();
}
catch
(
IOException
ioException
)
{
ioException
.
printStackTrace
();
}
String
[]
strs
=
line
.
split
(
String
.
valueOf
(
'\t'
));
try
{
fr
.
close
();
}
catch
(
IOException
ioException
)
{
ioException
.
printStackTrace
();
}
file
.
delete
();
try
{
if
(
strs
[
1
].
equals
(
byteToHexString
(
sha256
(
tfPwd
.
getText
()))))
{
MainMenu
mm
=
new
MainMenu
(
"Main Menu"
,
strs
[
0
],
tfPwd
.
getText
());
}
else
{
JOptionPane
.
showMessageDialog
(
null
,
"Password is invalid!"
);
}
}
catch
(
NoSuchAlgorithmException
noSuchAlgorithmException
)
{
noSuchAlgorithmException
.
printStackTrace
();
}
}
else
{
JOptionPane
.
showMessageDialog
(
null
,
tfId
.
getText
()
+
" has never signed Up!"
);
}
}
public
byte
[]
sha256
(
String
msg
)
throws
NoSuchAlgorithmException
{
MessageDigest
md
=
MessageDigest
.
getInstance
(
"SHA-256"
);
md
.
update
(
msg
.
getBytes
());
return
md
.
digest
();
}
public
String
byteToHexString
(
byte
[]
data
)
{
StringBuilder
sb
=
new
StringBuilder
();
for
(
byte
b
:
data
)
{
sb
.
append
(
String
.
format
(
"%02x"
,
b
));
}
return
sb
.
toString
();
}
}
}
\ No newline at end of file
DLPonUSB/src/cryptor/SignUp.java
0 → 100644
View file @
042085f
package
cryptor
;
import
javax.swing.*
;
import
java.awt.*
;
import
java.awt.event.ActionEvent
;
import
java.awt.event.ActionListener
;
import
java.awt.event.WindowAdapter
;
import
java.awt.event.WindowEvent
;
import
java.io.File
;
import
java.io.FileNotFoundException
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.security.GeneralSecurityException
;
import
java.security.MessageDigest
;
import
java.security.NoSuchAlgorithmException
;
class
SignUp
extends
Frame
{
Label
lid
;
Label
lpwd
;
TextField
tfId
;
TextField
tfPwd
;
Button
ok
;
SignUp
(
String
title
){
//Frame(String title)을 호출한다.
super
(
title
);
addWindowListener
(
new
WindowAdapter
()
{
@Override
public
void
windowClosing
(
WindowEvent
e
)
{
dispose
();
}
});
//Label의 text정렬을 오른쪽으로
lid
=
new
Label
(
"ID : "
,
Label
.
RIGHT
);
lpwd
=
new
Label
(
"Password : "
,
Label
.
RIGHT
);
//약 10개의 글자를 입력할 수 있는 TextField 생성.
tfId
=
new
TextField
(
10
);
tfPwd
=
new
TextField
(
10
);
//입력한 값 대신 '*'이 보이게 한다.
tfPwd
.
setEchoChar
(
'*'
);
ok
=
new
Button
(
"OK"
);
//OK버튼과 TextField에 이벤트처리를 위한 Listener를 추가해준다.
tfId
.
addActionListener
(
new
EventHandler
());
tfPwd
.
addActionListener
(
new
EventHandler
());
ok
.
addActionListener
(
new
EventHandler
());
//LayoutManager를 FlowLayout으로
setLayout
(
new
FlowLayout
());
//생성한 component들을 Frame에 포함시킨다.
add
(
lid
);
add
(
tfId
);
add
(
lpwd
);
add
(
tfPwd
);
add
(
ok
);
setSize
(
450
,
80
);
this
.
setLocationRelativeTo
(
null
);
//화면이 보이게 한다.
setVisible
(
true
);
}
public
static
void
main
(
String
args
[]){
SignUp
f
=
new
SignUp
(
"Sign Up"
);
}
class
EventHandler
implements
ActionListener
{
public
void
actionPerformed
(
ActionEvent
e
){
if
(
tfId
.
getText
().
length
()
<
1
||
tfPwd
.
getText
().
length
()
<
1
)
{
JOptionPane
.
showMessageDialog
(
null
,
"ID and password cannot be null."
);
return
;
}
String
passwd
=
tfId
.
getText
()
+
' '
+
tfPwd
.
getText
();
char
[]
password
=
passwd
.
toCharArray
();
String
dir
=
".\\Users\\"
+
tfId
.
getText
()
+
".txt"
;
String
dir2
=
".\\Users\\"
+
tfId
.
getText
()
+
".info"
;
File
f
=
new
File
(
dir2
);
if
(!
f
.
exists
())
{
dispose
();
File
file
=
new
File
(
dir
);
file
.
getParentFile
().
mkdir
();
try
{
file
.
createNewFile
();
}
catch
(
IOException
ioException
)
{
ioException
.
printStackTrace
();
}
FileOutputStream
fos
=
null
;
try
{
fos
=
new
FileOutputStream
(
file
);
}
catch
(
FileNotFoundException
fileNotFoundException
)
{
fileNotFoundException
.
printStackTrace
();
}
String
toWrite
=
null
;
try
{
toWrite
=
tfId
.
getText
()
+
'\t'
+
byteToHexString
(
sha256
(
tfPwd
.
getText
()));
}
catch
(
NoSuchAlgorithmException
noSuchAlgorithmException
)
{
noSuchAlgorithmException
.
printStackTrace
();
}
byte
[]
b
=
toWrite
.
getBytes
();
try
{
fos
.
write
(
b
);
}
catch
(
IOException
ioException
)
{
ioException
.
printStackTrace
();
}
try
{
fos
.
flush
();
}
catch
(
IOException
ioException
)
{
ioException
.
printStackTrace
();
}
try
{
fos
.
close
();
}
catch
(
IOException
ioException
)
{
ioException
.
printStackTrace
();
}
try
{
Cryptor
.
encrypt
(
dir
,
dir2
,
password
);
}
catch
(
IOException
ioException
)
{
ioException
.
printStackTrace
();
}
catch
(
GeneralSecurityException
generalSecurityException
)
{
generalSecurityException
.
printStackTrace
();
}
file
.
delete
();
}
else
{
JOptionPane
.
showMessageDialog
(
null
,
tfId
.
getText
()
+
" already exists!"
);
}
}
public
byte
[]
sha256
(
String
msg
)
throws
NoSuchAlgorithmException
{
MessageDigest
md
=
MessageDigest
.
getInstance
(
"SHA-256"
);
md
.
update
(
msg
.
getBytes
());
return
md
.
digest
();
}
public
String
byteToHexString
(
byte
[]
data
)
{
StringBuilder
sb
=
new
StringBuilder
();
for
(
byte
b
:
data
)
{
sb
.
append
(
String
.
format
(
"%02x"
,
b
));
}
return
sb
.
toString
();
}
}
}
\ No newline at end of file
Please
register
or
login
to post a comment