Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
legobackend
/
lego-manage
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
e77ef3f4
authored
2025-08-07 17:52:03 +0800
by
chentao
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
更换加密方法
1 parent
69deb321
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
69 additions
and
2 deletions
lego-admin/src/main/java/com/lego/ManageApplication.java
lego-common/src/main/java/com/lego/common/utils/EncryptUtils.java
lego-system/src/main/java/com/lego/system/service/impl/SysOssServiceImpl.java
lego-admin/src/main/java/com/lego/ManageApplication.java
0 → 100644
View file @
e77ef3f
package
com
.
lego
;
import
com.lego.common.utils.EncryptUtils
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileOutputStream
;
/**
* @author chentao
* @date 2025/8/7
*/
public
class
ManageApplication
{
public
static
void
main
(
String
[]
args
)
{
String
path1
=
"f:/1.mp4"
;
String
path2
=
"f:/2.mp4"
;
try
{
FileInputStream
inputStream
=
new
FileInputStream
(
path1
);
FileOutputStream
outputStream
=
new
FileOutputStream
(
path2
);
byte
[]
arr
=
new
byte
[
inputStream
.
available
()];
inputStream
.
read
(
arr
);
byte
[]
decrypt
=
EncryptUtils
.
decryptByAes
(
arr
);
outputStream
.
write
(
decrypt
);
inputStream
.
close
();
outputStream
.
close
();
}
catch
(
Exception
e
){
e
.
printStackTrace
();
}
}
}
lego-common/src/main/java/com/lego/common/utils/EncryptUtils.java
View file @
e77ef3f
...
...
@@ -12,6 +12,7 @@ import cn.hutool.crypto.asymmetric.SM2;
import
java.nio.charset.StandardCharsets
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Objects
;
/**
* 安全相关工具类
...
...
@@ -72,6 +73,18 @@ public class EncryptUtils {
return
SecureUtil
.
aes
(
password
.
getBytes
(
StandardCharsets
.
UTF_8
)).
encryptBase64
(
data
,
StandardCharsets
.
UTF_8
);
}
public
static
byte
[]
encryptByAes
(
byte
[]
data
,
String
password
)
{
if
(
StrUtil
.
isBlank
(
password
))
{
throw
new
IllegalArgumentException
(
"AES需要传入秘钥信息"
);
}
// aes算法的秘钥要求是16位、24位、32位
int
[]
array
=
{
16
,
24
,
32
};
if
(!
ArrayUtil
.
contains
(
array
,
password
.
length
()))
{
throw
new
IllegalArgumentException
(
"AES秘钥长度要求为16位、24位、32位"
);
}
return
SecureUtil
.
aes
(
password
.
getBytes
(
StandardCharsets
.
UTF_8
)).
encrypt
(
data
);
}
/**
* AES加密
*
...
...
@@ -82,6 +95,10 @@ public class EncryptUtils {
return
encryptByAes
(
data
,
AES_SECRET
);
}
public
static
byte
[]
encryptByAes
(
byte
[]
data
)
{
return
encryptByAes
(
data
,
AES_SECRET
);
}
/**
* AES加密
*
...
...
@@ -118,6 +135,18 @@ public class EncryptUtils {
* @param password 秘钥字符串
* @return 解密后字符串
*/
public
static
byte
[]
decryptByAes
(
byte
[]
data
,
String
password
)
{
if
(
StrUtil
.
isBlank
(
password
))
{
throw
new
IllegalArgumentException
(
"AES需要传入秘钥信息"
);
}
// aes算法的秘钥要求是16位、24位、32位
int
[]
array
=
{
16
,
24
,
32
};
if
(!
ArrayUtil
.
contains
(
array
,
password
.
length
()))
{
throw
new
IllegalArgumentException
(
"AES秘钥长度要求为16位、24位、32位"
);
}
return
SecureUtil
.
aes
(
password
.
getBytes
(
StandardCharsets
.
UTF_8
)).
decrypt
(
data
);
}
public
static
String
decryptByAes
(
String
data
,
String
password
)
{
if
(
StrUtil
.
isBlank
(
password
))
{
throw
new
IllegalArgumentException
(
"AES需要传入秘钥信息"
);
...
...
@@ -143,6 +172,13 @@ public class EncryptUtils {
return
""
;
}
public
static
byte
[]
decryptByAes
(
byte
[]
data
)
{
if
(
Objects
.
nonNull
(
data
))
{
return
decryptByAes
(
data
,
AES_SECRET
);
}
return
null
;
}
/**
* sm4加密
*
...
...
lego-system/src/main/java/com/lego/system/service/impl/SysOssServiceImpl.java
View file @
e77ef3f
...
...
@@ -211,8 +211,7 @@ public class SysOssServiceImpl implements ISysOssService, OssService {
UploadResult
uploadResult
;
try
{
if
(
".pdf"
.
equals
(
suffix
)
||
".mp4"
.
equals
(
suffix
)
||
".json"
.
equals
(
suffix
)
||
".ldr"
.
equals
(
suffix
))
{
String
temp
=
EncryptUtils
.
encryptByAes
(
StrUtil
.
str
(
file
.
getBytes
(),
StandardCharsets
.
UTF_8
));
byte
[]
encryptBytes
=
StrUtil
.
bytes
(
temp
,
CharsetUtil
.
CHARSET_UTF_8
);
byte
[]
encryptBytes
=
EncryptUtils
.
encryptByAes
(
file
.
getBytes
());
uploadResult
=
storage
.
uploadSuffix
(
encryptBytes
,
suffix
,
file
.
getContentType
());
}
else
{
...
...
Write
Preview
Styling with
Markdown
is supported
Attach a file
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 post a comment