Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
COMP90015-DSAss2-InfinityMonkeys-remaster
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
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ho Dac Hai
COMP90015-DSAss2-InfinityMonkeys-remaster
Merge requests
!39
EncryptDecrypt
Code
Review changes
Check out branch
Download
Patches
Plain diff
Expand sidebar
Merged
EncryptDecrypt
hai
into
master
Overview
0
Commits
1
Pipelines
0
Changes
1
Merged
EncryptDecrypt
Ho Dac Hai
requested to merge
hai
into
master
Oct 24, 2019
Overview
0
Commits
1
Pipelines
0
Changes
1
0
0
Merge request reports
Compare
master
master (base)
and
latest version
latest version
0145a574
1 commit,
Oct 24, 2019
1 file
+
59
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
src/remote/EncryptDecrypt.java
0 → 100644
+
59
−
0
View file @ 0145a574
Edit in single-file editor
Open in Web IDE
package
remote
;
import
javax.crypto.*
;
import
java.io.IOException
;
import
java.security.InvalidKeyException
;
import
java.security.NoSuchAlgorithmException
;
public
class
EncryptDecrypt
{
public
static
String
decryptString
(
SealedObject
sealedObject
,
SecretKey
key
){
String
nonSealedString
=
""
;
Cipher
cipher
=
null
;
try
{
cipher
=
Cipher
.
getInstance
(
"AES"
);
cipher
.
init
(
Cipher
.
DECRYPT_MODE
,
key
);
nonSealedString
=
(
String
)
sealedObject
.
getObject
(
cipher
);
}
catch
(
NoSuchAlgorithmException
e
)
{
e
.
printStackTrace
();
}
catch
(
NoSuchPaddingException
e
)
{
e
.
printStackTrace
();
}
catch
(
InvalidKeyException
e
)
{
e
.
printStackTrace
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
catch
(
IllegalBlockSizeException
e
)
{
e
.
printStackTrace
();
}
catch
(
BadPaddingException
e
)
{
e
.
printStackTrace
();
}
catch
(
ClassNotFoundException
e
)
{
e
.
printStackTrace
();
}
return
nonSealedString
;
}
public
static
SealedObject
encryptString
(
String
string
,
SecretKey
key
){
SealedObject
sealedObject
=
null
;
Cipher
cipher
=
null
;
try
{
cipher
=
Cipher
.
getInstance
(
"AES"
);
cipher
.
init
(
Cipher
.
ENCRYPT_MODE
,
key
);
sealedObject
=
new
SealedObject
(
string
,
cipher
);
}
catch
(
NoSuchAlgorithmException
e
)
{
e
.
printStackTrace
();
}
catch
(
NoSuchPaddingException
e
)
{
e
.
printStackTrace
();
}
catch
(
IllegalBlockSizeException
e
)
{
e
.
printStackTrace
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
catch
(
InvalidKeyException
e
)
{
e
.
printStackTrace
();
}
return
sealedObject
;
}
}
Loading