Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
Project
Project
Details
Activity
Releases
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
YZG
yzg-util
Commits
5d39575f
Commit
5d39575f
authored
Sep 13, 2021
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改实例化关系
parent
28384f7e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
6 deletions
+22
-6
DesHelper.java
.../src/main/java/com/yanzuoguang/util/helper/DesHelper.java
+20
-4
TestDes.java
yzg-util-base/src/test/java/helper/TestDes.java
+2
-2
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/helper/D
ES
Helper.java
→
yzg-util-base/src/main/java/com/yanzuoguang/util/helper/D
es
Helper.java
View file @
5d39575f
package
com
.
yanzuoguang
.
util
.
helper
;
package
com
.
yanzuoguang
.
util
.
helper
;
import
com.yanzuoguang.util.contants.SystemContants
;
import
com.yanzuoguang.util.exception.CodeException
;
import
javax.crypto.Cipher
;
import
javax.crypto.Cipher
;
import
javax.crypto.SecretKey
;
import
javax.crypto.SecretKey
;
import
javax.crypto.SecretKeyFactory
;
import
javax.crypto.SecretKeyFactory
;
import
javax.crypto.spec.DESKeySpec
;
import
javax.crypto.spec.DESKeySpec
;
import
java.io.UnsupportedEncodingException
;
import
java.security.Key
;
import
java.security.Key
;
import
java.security.SecureRandom
;
import
java.security.SecureRandom
;
...
@@ -12,7 +16,7 @@ import java.security.SecureRandom;
...
@@ -12,7 +16,7 @@ import java.security.SecureRandom;
*
*
* @author 颜佐光
* @author 颜佐光
*/
*/
public
class
D
ES
Helper
{
public
class
D
es
Helper
{
private
static
final
String
ALGORITHM_DES
=
"des"
;
private
static
final
String
ALGORITHM_DES
=
"des"
;
...
@@ -24,7 +28,13 @@ public class DESHelper {
...
@@ -24,7 +28,13 @@ public class DESHelper {
* @return byte[]
* @return byte[]
*/
*/
public
static
String
DESEncrypt
(
final
String
key
,
final
String
content
)
{
public
static
String
DESEncrypt
(
final
String
key
,
final
String
content
)
{
return
RsaHelper
.
encodeBase64
(
processCipher
(
content
.
getBytes
(),
getSecretKey
(
key
),
Cipher
.
ENCRYPT_MODE
,
ALGORITHM_DES
));
try
{
byte
[]
from
=
content
.
getBytes
(
SystemContants
.
UTF8
);
byte
[]
to
=
processCipher
(
from
,
getSecretKey
(
key
),
Cipher
.
ENCRYPT_MODE
,
ALGORITHM_DES
);
return
RsaHelper
.
encodeBase64
(
to
);
}
catch
(
UnsupportedEncodingException
ex
)
{
throw
new
CodeException
(
"加密失败:"
+
ex
.
getMessage
(),
ex
);
}
}
}
/**
/**
...
@@ -34,8 +44,14 @@ public class DESHelper {
...
@@ -34,8 +44,14 @@ public class DESHelper {
* @param encoderContent 已加密内容
* @param encoderContent 已加密内容
* @return byte[]
* @return byte[]
*/
*/
public
static
byte
[]
DESDecrypt
(
final
String
key
,
final
String
encoderContent
)
{
public
static
String
DESDecrypt
(
final
String
key
,
final
String
encoderContent
)
{
return
processCipher
(
RsaHelper
.
decodeBase64
(
encoderContent
),
getSecretKey
(
key
),
Cipher
.
DECRYPT_MODE
,
ALGORITHM_DES
);
try
{
byte
[]
from
=
RsaHelper
.
decodeBase64
(
encoderContent
);
byte
[]
to
=
processCipher
(
from
,
getSecretKey
(
key
),
Cipher
.
DECRYPT_MODE
,
ALGORITHM_DES
);
return
new
String
(
to
,
SystemContants
.
UTF8
);
}
catch
(
UnsupportedEncodingException
ex
)
{
throw
new
CodeException
(
"解密失败:"
+
ex
.
getMessage
(),
ex
);
}
}
}
/**
/**
...
...
yzg-util-base/src/test/java/helper/TestDes.java
View file @
5d39575f
package
helper
;
package
helper
;
import
com.yanzuoguang.util.helper.D
ES
Helper
;
import
com.yanzuoguang.util.helper.D
es
Helper
;
import
org.junit.Test
;
import
org.junit.Test
;
public
class
TestDes
{
public
class
TestDes
{
...
@@ -11,7 +11,7 @@ public class TestDes {
...
@@ -11,7 +11,7 @@ public class TestDes {
@Test
@Test
public
void
test
()
{
public
void
test
()
{
System
.
out
.
println
(
str
.
length
());
System
.
out
.
println
(
str
.
length
());
String
des
=
D
ES
Helper
.
DESEncrypt
(
pwd
,
str
);
String
des
=
D
es
Helper
.
DESEncrypt
(
pwd
,
str
);
System
.
out
.
println
(
des
.
length
());
System
.
out
.
println
(
des
.
length
());
System
.
out
.
println
(
des
);
System
.
out
.
println
(
des
);
}
}
...
...
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