Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
I
ioc_sixiang_license
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
zengtianlai3
ioc_sixiang_license
Commits
a1e6982e
Commit
a1e6982e
authored
Jul 15, 2022
by
zengtianlai3
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
数据脱敏、加密
parent
23386991
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
202 additions
and
2 deletions
+202
-2
pom.xml
license/pom.xml
+10
-0
EncryptController.java
...ava/iot/sixiang/license/controller/EncryptController.java
+59
-0
MaskingController.java
...ava/iot/sixiang/license/controller/MaskingController.java
+48
-0
EncryptVo.java
...src/main/java/iot/sixiang/license/model/vo/EncryptVo.java
+17
-0
MaskingVo.java
...src/main/java/iot/sixiang/license/model/vo/MaskingVo.java
+19
-0
CommonUtil.java
...se/src/main/java/iot/sixiang/license/util/CommonUtil.java
+44
-0
application-dev.yml
license/src/main/resources/application-dev.yml
+5
-2
No files found.
license/pom.xml
View file @
a1e6982e
...
@@ -105,6 +105,16 @@
...
@@ -105,6 +105,16 @@
<artifactId>
jasypt-spring-boot-starter
</artifactId>
<artifactId>
jasypt-spring-boot-starter
</artifactId>
<version>
3.0.3
</version>
<version>
3.0.3
</version>
</dependency>
</dependency>
<dependency>
<groupId>
cn.hutool
</groupId>
<artifactId>
hutool-all
</artifactId>
<version>
5.7.22
</version>
</dependency>
<dependency>
<groupId>
org.bouncycastle
</groupId>
<artifactId>
bcprov-jdk15to18
</artifactId>
<version>
1.69
</version>
</dependency>
</dependencies>
</dependencies>
<build>
<build>
...
...
license/src/main/java/iot/sixiang/license/controller/EncryptController.java
0 → 100644
View file @
a1e6982e
package
iot
.
sixiang
.
license
.
controller
;
import
cn.hutool.crypto.SmUtil
;
import
cn.hutool.crypto.symmetric.SM4
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
iot.sixiang.license.model.ResResult
;
import
iot.sixiang.license.model.vo.EncryptVo
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Value
;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
java.lang.reflect.InvocationTargetException
;
/**
* Title: EncryptController
* Description: TODO
*
* @author tianlai3
* @date 2022-07-13 01:05:23
*/
@Slf4j
@RestController
@RequestMapping
(
"/iot_license"
)
@Api
(
value
=
"数据加密"
,
tags
=
{
"数据加密"
})
public
class
EncryptController
{
@Value
(
"${other.sm4-key}"
)
private
String
sm4Key
;
@ApiOperation
(
value
=
"数据加密"
)
@PostMapping
(
"/encrypt"
)
public
ResResult
<
EncryptVo
>
encrypt
(
@RequestBody
EncryptVo
encryptVo
)
{
if
(
StringUtils
.
isEmpty
(
encryptVo
.
getMessage
()))
{
return
ResResult
.
failed
().
setMsgValue
(
"输入的信息不能为空"
);
}
SM4
sm4
=
SmUtil
.
sm4
(
sm4Key
.
getBytes
());
EncryptVo
vo
=
new
EncryptVo
();
vo
.
setMessage
(
sm4
.
encryptBase64
(
encryptVo
.
getMessage
()));
return
ResResult
.
success
().
goRecord
(
vo
);
}
@ApiOperation
(
value
=
"数据解密"
)
@PostMapping
(
"/decrypt"
)
public
ResResult
<
EncryptVo
>
decrypt
(
@RequestBody
EncryptVo
encryptVo
)
{
if
(
StringUtils
.
isEmpty
(
encryptVo
.
getMessage
()))
{
return
ResResult
.
failed
().
setMsgValue
(
"输入的信息不能为空"
);
}
SM4
sm4
=
SmUtil
.
sm4
(
sm4Key
.
getBytes
());
String
message
=
sm4
.
decryptStr
(
encryptVo
.
getMessage
());
EncryptVo
vo
=
new
EncryptVo
();
vo
.
setMessage
(
message
);
return
ResResult
.
success
().
goRecord
(
vo
);
}
}
license/src/main/java/iot/sixiang/license/controller/MaskingController.java
0 → 100644
View file @
a1e6982e
package
iot
.
sixiang
.
license
.
controller
;
import
cn.hutool.core.util.IdcardUtil
;
import
io.swagger.annotations.Api
;
import
io.swagger.annotations.ApiOperation
;
import
iot.sixiang.license.model.ResResult
;
import
iot.sixiang.license.model.vo.MaskingVo
;
import
iot.sixiang.license.util.CommonUtil
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.util.StringUtils
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
/**
* Title: MaskingController
* Description: TODO
*
* @author tianlai3
* @date 2022-07-13 01:40:24
*/
@Slf4j
@RestController
@RequestMapping
(
"/iot_license"
)
@Api
(
value
=
"数据脱敏"
,
tags
=
{
"数据脱敏"
})
public
class
MaskingController
{
@ApiOperation
(
value
=
"数据脱敏"
)
@PostMapping
(
"/desensitize"
)
public
ResResult
<
MaskingVo
>
encrypt
(
@RequestBody
MaskingVo
maskingVo
)
{
if
(!
IdcardUtil
.
isValidCard
(
maskingVo
.
getIdCard
()))
{
return
ResResult
.
failed
().
setMsgValue
(
"身份证格式出错"
);
}
if
(
StringUtils
.
isEmpty
(
maskingVo
.
getUserName
()))
{
return
ResResult
.
failed
().
setMsgValue
(
"用户姓名不能为空"
);
}
MaskingVo
vo
=
new
MaskingVo
();
vo
.
setUserName
(
CommonUtil
.
nameDesensitization
(
maskingVo
.
getUserName
()));
vo
.
setIdCard
(
CommonUtil
.
idCardEncrypt
(
maskingVo
.
getIdCard
()));
return
ResResult
.
success
().
goRecord
(
vo
);
}
}
license/src/main/java/iot/sixiang/license/model/vo/EncryptVo.java
0 → 100644
View file @
a1e6982e
package
iot
.
sixiang
.
license
.
model
.
vo
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
/**
* Title: EncryptVo
* Description: TODO
*
* @author tianlai3
* @date 2022-07-13 01:10:10
*/
@Data
public
class
EncryptVo
{
@ApiModelProperty
(
value
=
"数据"
)
String
message
;
}
license/src/main/java/iot/sixiang/license/model/vo/MaskingVo.java
0 → 100644
View file @
a1e6982e
package
iot
.
sixiang
.
license
.
model
.
vo
;
import
io.swagger.annotations.ApiModelProperty
;
import
lombok.Data
;
/**
* Title: MaskingVo
* Description: TODO
*
* @author tianlai3
* @date 2022-07-13 01:42:04
*/
@Data
public
class
MaskingVo
{
@ApiModelProperty
(
value
=
"用户姓名"
)
String
userName
;
@ApiModelProperty
(
value
=
"身份证号"
)
String
idCard
;
}
license/src/main/java/iot/sixiang/license/util/CommonUtil.java
View file @
a1e6982e
...
@@ -2,6 +2,7 @@ package iot.sixiang.license.util;
...
@@ -2,6 +2,7 @@ package iot.sixiang.license.util;
import
iot.sixiang.license.consts.Consts
;
import
iot.sixiang.license.consts.Consts
;
import
lombok.extern.slf4j.Slf4j
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.boot.system.ApplicationHome
;
import
org.springframework.boot.system.ApplicationHome
;
import
java.io.File
;
import
java.io.File
;
...
@@ -94,5 +95,48 @@ public class CommonUtil {
...
@@ -94,5 +95,48 @@ public class CommonUtil {
}
}
return
""
;
return
""
;
}
}
/**
* 名字脱敏
* 规则,张三丰,脱敏为:张*丰
*
* @param name
* @return
*/
public
static
String
nameDesensitization
(
String
name
)
{
// 已经脱敏了直接返回
if
(
name
==
null
||
name
.
contains
(
"*"
))
{
return
name
;
}
if
(
name
==
null
||
name
.
isEmpty
())
{
return
""
;
}
String
myName
=
null
;
char
[]
chars
=
name
.
toCharArray
();
if
(
chars
.
length
==
1
)
{
myName
=
name
;
}
if
(
chars
.
length
==
2
)
{
myName
=
StringUtils
.
overlay
(
name
,
"*"
,
1
,
2
);
}
if
(
chars
.
length
>
2
)
{
int
n
=
chars
.
length
-
2
;
StringBuilder
s
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
n
;
i
++)
{
s
.
append
(
"*"
);
}
myName
=
StringUtils
.
overlay
(
name
,
String
.
valueOf
(
s
),
1
,
chars
.
length
-
1
);
}
return
myName
;
}
//身份证前三后四脱敏
public
static
String
idCardEncrypt
(
String
idcard
)
{
if
(
idcard
==
null
||
idcard
.
length
()
==
0
||
idcard
.
contains
(
"*"
))
return
idcard
;
if
(
StringUtils
.
isEmpty
(
idcard
)
||
(
idcard
.
length
()
<
8
))
{
return
idcard
;
}
String
res
=
StringUtils
.
overlay
(
idcard
,
"**************"
,
0
,
14
);
return
res
;
}
}
}
license/src/main/resources/application-dev.yml
View file @
a1e6982e
...
@@ -8,9 +8,12 @@ spring:
...
@@ -8,9 +8,12 @@ spring:
driver-class-name
:
com.mysql.cj.jdbc.Driver
driver-class-name
:
com.mysql.cj.jdbc.Driver
url
:
jdbc:mysql://localhost:3306/iot_license?serverTimezone=GMT%2B8
url
:
jdbc:mysql://localhost:3306/iot_license?serverTimezone=GMT%2B8
username
:
root
username
:
root
password
:
ENC(RgKt4Sc9ar9R590ESUZsSg==)
password
:
123456
mybatis-plus
:
mybatis-plus
:
mapper-locations
:
classpath:/mapper/**.xml
mapper-locations
:
classpath:/mapper/**.xml
type-aliases-package
:
iot.sixiang.license.entity
type-aliases-package
:
iot.sixiang.license.entity
knife4j
:
knife4j
:
enable
:
true
enable
:
true
\ No newline at end of file
other
:
sm4-key
:
sixiang890123456
\ No newline at end of file
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