Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wecloud_im_server
Overview
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hewei
wecloud_im_server
Commits
c0b405bf
Commit
c0b405bf
authored
Apr 24, 2022
by
罗长华
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
使用java.util.Base64替换sun.misc.BASE64Decoder和sun.misc.BASE64Encode
parent
62996f9f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
9 deletions
+12
-9
core/src/main/java/com/wecloud/utils/AesUtil.java
+7
-5
core/src/main/java/com/wecloud/utils/Base64Util.java
+5
-4
No files found.
core/src/main/java/com/wecloud/utils/AesUtil.java
View file @
c0b405bf
package
com
.
wecloud
.
utils
;
import
io.geekidea.springbootplus.framework.common.exception.BusinessException
;
import
sun.misc.BASE64Decoder
;
import
sun.misc.BASE64Encoder
;
import
java.util.Base64
;
import
javax.crypto.Cipher
;
import
javax.crypto.spec.SecretKeySpec
;
...
...
@@ -30,7 +30,8 @@ public class AesUtil {
cipher
.
init
(
Cipher
.
ENCRYPT_MODE
,
skeySpec
);
byte
[]
encrypted
=
cipher
.
doFinal
(
sSrc
.
getBytes
(
"utf-8"
));
// 此处使用BASE64做转码功能,同时能起到2次加密的作用。
return
new
BASE64Encoder
().
encode
(
encrypted
);
Base64
.
Encoder
encoder
=
Base64
.
getEncoder
();
return
encoder
.
encodeToString
(
encrypted
);
}
catch
(
Exception
e
)
{
throw
new
BusinessException
(
"系统异常,稍后重试"
);
}
...
...
@@ -48,10 +49,11 @@ public class AesUtil {
SecretKeySpec
skeySpec
=
new
SecretKeySpec
(
raw
,
"AES"
);
Cipher
cipher
=
Cipher
.
getInstance
(
"AES/ECB/PKCS5Padding"
);
cipher
.
init
(
Cipher
.
DECRYPT_MODE
,
skeySpec
);
byte
[]
encrypted1
=
new
BASE64Decoder
().
decodeBuffer
(
sSrc
);
//先用base64解密
Base64
.
Decoder
decoder
=
Base64
.
getDecoder
();
byte
[]
encrypted1
=
decoder
.
decode
(
sSrc
);
//先用base64解密
try
{
byte
[]
original
=
cipher
.
doFinal
(
encrypted1
);
String
originalString
=
new
String
(
original
,
"utf-8"
);
String
originalString
=
new
String
(
original
,
"utf-8"
);
return
originalString
;
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
e
.
toString
());
...
...
core/src/main/java/com/wecloud/utils/Base64Util.java
View file @
c0b405bf
package
com
.
wecloud
.
utils
;
import
sun.misc.BASE64Decoder
;
import
sun.misc.BASE64Encoder
;
import
java.util.Base64
;
/**
* @Author wenzhida
...
...
@@ -17,7 +16,8 @@ public class Base64Util {
* @throws Exception
*/
public
static
byte
[]
decryBASE64
(
String
key
)
throws
Exception
{
return
(
new
BASE64Decoder
()).
decodeBuffer
(
key
);
Base64
.
Decoder
decoder
=
Base64
.
getDecoder
();
return
decoder
.
decode
(
key
);
}
/***
...
...
@@ -27,7 +27,8 @@ public class Base64Util {
* @throws Exception
*/
public
static
String
encryptBASE64
(
byte
[]
key
)
throws
Exception
{
return
(
new
BASE64Encoder
()).
encode
(
key
);
Base64
.
Encoder
encoder
=
Base64
.
getEncoder
();
return
encoder
.
encodeToString
(
key
);
}
}
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