Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yd-backend
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
AutogeneralShanghai
yd-backend
Commits
fe29ca07
Commit
fe29ca07
authored
Apr 22, 2020
by
Simon Cheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DES加解密方法
parent
245471ab
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
267 additions
and
24 deletions
+267
-24
yd-api/src/main/java/com/yd/api/security/DataSecurityController.java
+48
-0
yd-api/src/main/java/com/yd/api/security/vo/ConvertTable.java
+21
-0
yd-api/src/main/java/com/yd/api/security/vo/ConvertTableList.java
+47
-0
yd-api/src/main/java/com/yd/api/security/vo/DESCommonVO.java
+30
-0
yd-api/src/main/java/com/yd/api/security/vo/DesDecryptRequestVO.java
+4
-0
yd-api/src/main/java/com/yd/api/security/vo/DesDecryptResponseVO.java
+24
-0
yd-api/src/main/java/com/yd/api/security/vo/DesEncryptRequestVO.java
+22
-0
yd-api/src/main/java/com/yd/api/security/vo/DesEncryptResponseVO.java
+24
-0
yd-api/src/main/java/com/yd/util/deshandler/DESTypeHandler.java
+47
-24
No files found.
yd-api/src/main/java/com/yd/api/security/DataSecurityController.java
0 → 100644
View file @
fe29ca07
package
com
.
yd
.
api
.
security
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
com.yd.api.result.JsonResult
;
import
com.yd.api.security.vo.DESCommonVO
;
import
com.yd.util.deshandler.DESTypeHandler
;
@RestController
@RequestMapping
(
value
=
"/data/security"
)
public
class
DataSecurityController
{
@RequestMapping
(
"/dataencrypt"
)
public
Object
encrypt
(
@RequestBody
DESCommonVO
requestVO
)
throws
Exception
{
JsonResult
result
=
new
JsonResult
();
String
resultString
=
""
;
try
{
DESTypeHandler
jpaCryptoConverter
=
new
DESTypeHandler
();
resultString
=
jpaCryptoConverter
.
encode
((
requestVO
.
getContent
()));
requestVO
.
setEncrypted
(
resultString
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
result
.
setData
(
requestVO
);
return
result
;
}
@RequestMapping
(
"/datadecrypt"
)
public
Object
Decrypt
(
@RequestBody
DESCommonVO
requestVO
)
throws
Exception
{
JsonResult
result
=
new
JsonResult
();
String
content
=
""
;
try
{
DESTypeHandler
jpaCryptoConverter
=
new
DESTypeHandler
();
content
=
jpaCryptoConverter
.
decode
(
requestVO
.
getEncrypted
());
requestVO
.
setContent
(
content
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
result
.
setData
(
requestVO
);
return
result
;
}
}
yd-api/src/main/java/com/yd/api/security/vo/ConvertTable.java
0 → 100644
View file @
fe29ca07
package
com
.
yd
.
api
.
security
.
vo
;
import
java.util.List
;
public
class
ConvertTable
{
private
String
tableName
;
//表名
private
List
<
String
>
fields
;
public
String
getTableName
()
{
return
tableName
;
}
public
void
setTableName
(
String
tableName
)
{
this
.
tableName
=
tableName
;
}
public
List
<
String
>
getFields
()
{
return
fields
;
}
public
void
setFields
(
List
<
String
>
fields
)
{
this
.
fields
=
fields
;
}
}
yd-api/src/main/java/com/yd/api/security/vo/ConvertTableList.java
0 → 100644
View file @
fe29ca07
package
com
.
yd
.
api
.
security
.
vo
;
import
java.util.List
;
import
com.yd.api.result.CommonResult
;
import
com.yd.util.page.PaginationInfo
;
public
class
ConvertTableList
{
private
List
<
ConvertTable
>
convertTables
;
private
CommonResult
commonResult
;
private
String
dbName
;
//数据库名
private
String
operate
;
//1.加密(DataEncrypt)2.解密(DataDecrypt)
public
String
getOperate
()
{
return
operate
;
}
public
void
setOperate
(
String
operate
)
{
this
.
operate
=
operate
;
}
private
PaginationInfo
paginationInfo
;
public
PaginationInfo
getPaginationInfo
()
{
return
paginationInfo
;
}
public
void
setPaginationInfo
(
PaginationInfo
paginationInfo
)
{
this
.
paginationInfo
=
paginationInfo
;
}
public
List
<
ConvertTable
>
getConvertTables
()
{
return
convertTables
;
}
public
void
setConvertTables
(
List
<
ConvertTable
>
convertTables
)
{
this
.
convertTables
=
convertTables
;
}
public
CommonResult
getCommonResult
()
{
return
commonResult
;
}
public
void
setCommonResult
(
CommonResult
commonResult
)
{
this
.
commonResult
=
commonResult
;
}
public
String
getDbName
()
{
return
dbName
;
}
public
void
setDbName
(
String
dbName
)
{
this
.
dbName
=
dbName
;
}
}
yd-api/src/main/java/com/yd/api/security/vo/DESCommonVO.java
0 → 100644
View file @
fe29ca07
package
com
.
yd
.
api
.
security
.
vo
;
import
java.io.Serializable
;
public
class
DESCommonVO
implements
Serializable
{
/**
*
*/
private
static
final
long
serialVersionUID
=
1L
;
private
String
content
;
private
String
encrypted
;
public
String
getContent
()
{
return
content
;
}
public
void
setContent
(
String
content
)
{
this
.
content
=
content
;
}
public
String
getEncrypted
()
{
return
encrypted
;
}
public
void
setEncrypted
(
String
encrypt
)
{
encrypted
=
encrypt
;
}
}
yd-api/src/main/java/com/yd/api/security/vo/DesDecryptRequestVO.java
0 → 100644
View file @
fe29ca07
package
com
.
yd
.
api
.
security
.
vo
;
public
class
DesDecryptRequestVO
{
}
yd-api/src/main/java/com/yd/api/security/vo/DesDecryptResponseVO.java
0 → 100644
View file @
fe29ca07
package
com
.
yd
.
api
.
security
.
vo
;
import
com.yd.api.result.CommonResult
;
public
class
DesDecryptResponseVO
{
private
String
desDecryptResult
;
private
CommonResult
commonResult
;
public
String
getDesDecryptResult
()
{
return
desDecryptResult
;
}
public
void
setDesDecryptResult
(
String
desDecryptResult
)
{
this
.
desDecryptResult
=
desDecryptResult
;
}
public
CommonResult
getCommonResult
()
{
return
commonResult
;
}
public
void
setCommonResult
(
CommonResult
commonResult
)
{
this
.
commonResult
=
commonResult
;
}
}
yd-api/src/main/java/com/yd/api/security/vo/DesEncryptRequestVO.java
0 → 100644
View file @
fe29ca07
package
com
.
yd
.
api
.
security
.
vo
;
public
class
DesEncryptRequestVO
{
private
String
encryptString
;
private
String
type
;
public
String
getEncryptString
()
{
return
encryptString
;
}
public
void
setEncryptString
(
String
encryptString
)
{
this
.
encryptString
=
encryptString
;
}
public
String
getType
()
{
return
type
;
}
public
void
setType
(
String
type
)
{
this
.
type
=
type
;
}
}
yd-api/src/main/java/com/yd/api/security/vo/DesEncryptResponseVO.java
0 → 100644
View file @
fe29ca07
package
com
.
yd
.
api
.
security
.
vo
;
import
com.yd.api.result.CommonResult
;
public
class
DesEncryptResponseVO
{
private
String
encryptResult
;
private
CommonResult
commonResult
;
public
String
getEncryptResult
()
{
return
encryptResult
;
}
public
void
setEncryptResult
(
String
encryptResult
)
{
this
.
encryptResult
=
encryptResult
;
}
public
CommonResult
getCommonResult
()
{
return
commonResult
;
}
public
void
setCommonResult
(
CommonResult
commonResult
)
{
this
.
commonResult
=
commonResult
;
}
}
yd-api/src/main/java/com/yd/util/deshandler/DESTypeHandler.java
View file @
fe29ca07
...
...
@@ -32,30 +32,19 @@ public class DESTypeHandler extends BaseTypeHandler<Object> {
@Override
public
void
setNonNullParameter
(
PreparedStatement
ps
,
int
i
,
Object
parameter
,
JdbcType
jdbcType
)
throws
SQLException
{
sensitiveenabled
=
Boolean
.
valueOf
(
properties
.
get
(
secret_property_enabled_key
).
toString
());
if
(
sensitiveenabled
==
false
)
{
return
;
}
if
(
parameter
==
null
)
{
return
;
}
sensitivekey
=
(
String
)
properties
.
get
(
secret_property_key
);
DESUtils
des
;
String
result
=
null
;
try
{
des
=
new
DESUtils
(
sensitivekey
,
"utf-8"
);
if
(
parameter
!=
null
)
{
result
=
des
.
encode
((
String
)
parameter
);
}
ps
.
setString
(
i
,
result
);
}
catch
(
Exception
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
if
(
parameter
!=
null
)
{
result
=
encode
((
String
)
parameter
);
}
ps
.
setString
(
i
,
result
);
}
@Override
...
...
@@ -82,14 +71,47 @@ public class DESTypeHandler extends BaseTypeHandler<Object> {
String
result
=
decode
(
columnValue
);
return
result
;
}
private
String
decode
(
String
columnValue
)
{
/**
* 解密
* @param context
* @return
* @throws SQLException
*/
public
String
encode
(
String
context
)
throws
SQLException
{
sensitiveenabled
=
Boolean
.
valueOf
(
properties
.
get
(
secret_property_enabled_key
).
toString
());
if
(
sensitiveenabled
==
false
)
{
return
null
;
}
sensitivekey
=
(
String
)
properties
.
get
(
secret_property_key
);
DESUtils
des
;
String
result
=
null
;
try
{
des
=
new
DESUtils
(
sensitivekey
,
"utf-8"
);
if
(
context
!=
null
)
{
result
=
des
.
encode
((
String
)
context
);
}
}
catch
(
Exception
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
return
result
;
}
/**
* 解密
* @param columnValue
* @return
*/
public
String
decode
(
String
encrypted
)
{
sensitiveenabled
=
Boolean
.
valueOf
(
properties
.
get
(
secret_property_enabled_key
).
toString
());
if
(
sensitiveenabled
==
false
)
{
return
columnValue
;
return
encrypted
;
}
if
(
columnValue
==
null
)
if
(
encrypted
==
null
)
{
return
null
;
}
...
...
@@ -98,14 +120,15 @@ public class DESTypeHandler extends BaseTypeHandler<Object> {
String
result
=
null
;
try
{
des
=
new
DESUtils
(
sensitivekey
,
"utf-8"
);
if
(
columnValue
!=
null
)
if
(
encrypted
!=
null
)
{
result
=
des
.
decode
(
columnValue
);
result
=
des
.
decode
(
encrypted
);
}
}
catch
(
Exception
e
)
{
// TODO Auto-generated catch block
e
.
printStackTrace
();
}
return
result
;
}
...
...
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