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
d47a7fcf
Commit
d47a7fcf
authored
Sep 08, 2022
by
yanzg
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'ver1.1' of
http://192.168.0.204/yzg/yzg-util
parents
038d27d7
47d4b9e0
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
162 additions
and
12 deletions
+162
-12
RsaHelper.java
.../src/main/java/com/yanzuoguang/util/helper/RsaHelper.java
+6
-10
TestCalc.java
yzg-util-base/src/test/java/helper/TestCalc.java
+21
-0
TestJsonHelper.java
yzg-util-base/src/test/java/helper/TestJsonHelper.java
+132
-0
TestRsa.java
yzg-util-base/src/test/java/helper/TestRsa.java
+1
-1
MqServiceImpl.java
...n/java/com/yanzuoguang/mq/service/impl/MqServiceImpl.java
+2
-1
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/helper/RsaHelper.java
View file @
d47a7fcf
...
@@ -2,9 +2,7 @@ package com.yanzuoguang.util.helper;
...
@@ -2,9 +2,7 @@ package com.yanzuoguang.util.helper;
import
com.yanzuoguang.util.YzgError
;
import
com.yanzuoguang.util.YzgError
;
import
com.yanzuoguang.util.contants.SystemContants
;
import
com.yanzuoguang.util.contants.SystemContants
;
import
com.yanzuoguang.util.exception.CodeException
;
import
com.yanzuoguang.util.log.Log
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.springframework.util.Base64Utils
;
import
org.springframework.util.Base64Utils
;
import
javax.crypto.Cipher
;
import
javax.crypto.Cipher
;
...
@@ -34,8 +32,6 @@ import java.security.spec.X509EncodedKeySpec;
...
@@ -34,8 +32,6 @@ import java.security.spec.X509EncodedKeySpec;
*/
*/
public
final
class
RsaHelper
{
public
final
class
RsaHelper
{
private
static
final
Logger
logger
=
LoggerFactory
.
getLogger
(
RsaHelper
.
class
);
private
static
final
String
ALGORITHM_RSA
=
"RSA"
;
private
static
final
String
ALGORITHM_RSA
=
"RSA"
;
private
static
final
String
ALGORITHM_SIGN
=
"MD5withRSA"
;
private
static
final
String
ALGORITHM_SIGN
=
"MD5withRSA"
;
...
@@ -96,10 +92,10 @@ public final class RsaHelper {
...
@@ -96,10 +92,10 @@ public final class RsaHelper {
byte
[]
keyBs
=
rsaPublicKey
.
getEncoded
();
byte
[]
keyBs
=
rsaPublicKey
.
getEncoded
();
String
publicKey
=
encodeBase64
(
keyBs
);
String
publicKey
=
encodeBase64
(
keyBs
);
logger
.
info
(
"生成的公钥:\t{}
"
,
publicKey
);
Log
.
info
(
RsaHelper
.
class
,
"生成的公钥:\t %s
"
,
publicKey
);
keyBs
=
rsaPrivateKey
.
getEncoded
();
keyBs
=
rsaPrivateKey
.
getEncoded
();
String
privateKey
=
encodeBase64
(
keyBs
);
String
privateKey
=
encodeBase64
(
keyBs
);
logger
.
info
(
"生成的私钥:\t{}
"
,
privateKey
);
Log
.
info
(
RsaHelper
.
class
,
"生成的私钥:\t %s
"
,
privateKey
);
}
catch
(
Exception
ex
)
{
}
catch
(
Exception
ex
)
{
throw
new
RuntimeException
(
ex
);
throw
new
RuntimeException
(
ex
);
}
}
...
@@ -204,9 +200,9 @@ public final class RsaHelper {
...
@@ -204,9 +200,9 @@ public final class RsaHelper {
signature
.
initVerify
(
publicKey
);
signature
.
initVerify
(
publicKey
);
signature
.
update
(
target
.
getBytes
(
SystemContants
.
UTF8
));
signature
.
update
(
target
.
getBytes
(
SystemContants
.
UTF8
));
if
(
signature
.
verify
(
decodeBase64
(
sign
)))
{
if
(
signature
.
verify
(
decodeBase64
(
sign
)))
{
logger
.
info
(
"sign true"
);
Log
.
info
(
RsaHelper
.
class
,
"sign true"
);
}
else
{
}
else
{
logger
.
info
(
"sign false"
);
Log
.
info
(
RsaHelper
.
class
,
"sign false"
);
}
}
}
catch
(
Exception
ex
)
{
}
catch
(
Exception
ex
)
{
throw
new
RuntimeException
(
ex
);
throw
new
RuntimeException
(
ex
);
...
@@ -265,7 +261,7 @@ public final class RsaHelper {
...
@@ -265,7 +261,7 @@ public final class RsaHelper {
return
new
String
(
to
,
SystemContants
.
UTF8
);
return
new
String
(
to
,
SystemContants
.
UTF8
);
}
catch
(
Exception
ex
)
{
}
catch
(
Exception
ex
)
{
throw
YzgError
.
getRuntimeException
(
ex
,
"056"
,
ex
.
getMessage
());
throw
YzgError
.
getRuntimeException
(
ex
,
"056"
,
ex
.
getMessage
());
}
}
}
}
...
...
yzg-util-base/src/test/java/helper/TestCalc.java
0 → 100644
View file @
d47a7fcf
package
helper
;
import
com.yanzuoguang.util.helper.CalcHelper
;
import
com.yanzuoguang.util.helper.RsaHelper
;
import
org.junit.Assert
;
import
org.junit.Test
;
public
class
TestCalc
{
@Test
public
void
test
()
throws
Exception
{
double
d1
=
0.1
;
double
d2
=
0.2
;
double
d3
=
CalcHelper
.
add
(
d1
,
d2
);
Assert
.
assertTrue
(
CalcHelper
.
equals
(
d3
,
0.3
));
double
d4
=
d1
+
d2
;
Assert
.
assertFalse
(
CalcHelper
.
equals
(
d4
,
0.3
));
}
}
yzg-util-base/src/test/java/helper/TestJsonHelper.java
0 → 100644
View file @
d47a7fcf
package
helper
;
import
com.alibaba.fastjson.TypeReference
;
import
com.yanzuoguang.util.helper.JsonHelper
;
import
org.junit.Assert
;
import
org.junit.Test
;
import
java.util.ArrayList
;
import
java.util.List
;
public
class
TestJsonHelper
{
@Test
public
void
test
()
{
Fanxing
<
FanxingData
>
from
=
new
Fanxing
<>(
new
FanxingData
(
"颜佐光"
));
from
.
setList
(
null
);
from
.
setListNull
(
null
);
String
json
=
JsonHelper
.
serialize
(
from
);
Fanxing
<
FanxingData
>
to
=
JsonHelper
.
deserialize
(
json
,
new
TypeReference
<
Fanxing
<
FanxingData
>>()
{
});
Assert
.
assertNotEquals
(
from
,
to
);
Assert
.
assertNotEquals
(
from
.
getData
(),
to
.
getData
());
Assert
.
assertEquals
(
from
.
getData
().
getName
(),
to
.
getData
().
getName
());
Assert
.
assertNotNull
(
to
.
getVal
());
Assert
.
assertNotNull
(
to
.
getList
());
Assert
.
assertNull
(
to
.
getListNull
());
}
@Test
public
void
test1
()
{
Fanxing
<
Fanxing
<
FanxingData
>>
from
=
new
Fanxing
<>(
new
Fanxing
<>(
new
FanxingData
(
"颜佐光"
)));
from
.
setList
(
null
);
from
.
setListNull
(
null
);
String
json
=
JsonHelper
.
serialize
(
from
);
Fanxing
<
Fanxing
<
FanxingData
>>
to
=
JsonHelper
.
deserialize
(
json
,
new
TypeReference
<
Fanxing
<
Fanxing
<
FanxingData
>>>()
{
});
Assert
.
assertNotEquals
(
from
,
to
);
Assert
.
assertNotEquals
(
from
.
getData
(),
to
.
getData
());
Assert
.
assertEquals
(
from
.
getData
().
getData
().
getName
(),
to
.
getData
().
getData
().
getName
());
Assert
.
assertNotNull
(
to
.
getList
());
Assert
.
assertNull
(
to
.
getListNull
());
}
}
class
Fanxing
<
T
>
{
private
T
data
;
/**
* 用于检测参数可能为null,提醒必须传参数
*/
private
Integer
val
=
0
;
/**
* null值反序列化后不会为null,这里不需要提醒传参数为null,一般都是通过数量来控制的
*/
private
List
<
T
>
list
=
new
ArrayList
<>();
/**
* null值反序列化后后会为null
*/
private
List
<
T
>
listNull
;
/**
* 当没有无参构造函数时无法序列化
*/
public
Fanxing
()
{
}
public
Fanxing
(
T
data
)
{
this
.
data
=
data
;
}
public
T
getData
()
{
return
data
;
}
public
Integer
getVal
()
{
return
val
;
}
public
void
setVal
(
Integer
val
)
{
this
.
val
=
val
;
}
public
void
setData
(
T
data
)
{
this
.
data
=
data
;
}
public
List
<
T
>
getList
()
{
return
list
;
}
public
void
setList
(
List
<
T
>
list
)
{
this
.
list
=
list
;
}
public
List
<
T
>
getListNull
()
{
return
listNull
;
}
public
void
setListNull
(
List
<
T
>
listNull
)
{
this
.
listNull
=
listNull
;
}
}
class
FanxingData
{
private
String
name
;
/**
* 当没有无参构造函数时无法序列化
*/
public
FanxingData
()
{
}
public
FanxingData
(
String
name
)
{
this
.
name
=
name
;
}
public
String
getName
()
{
return
name
;
}
public
void
setName
(
String
name
)
{
this
.
name
=
name
;
}
}
\ No newline at end of file
yzg-util-base/src/test/java/helper/TestRsa.java
View file @
d47a7fcf
...
@@ -17,7 +17,7 @@ public class TestRsa {
...
@@ -17,7 +17,7 @@ public class TestRsa {
String
privateKey
=
"MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBALcZ2sh1PaU5uVJqVeDDgGOe/t/bJsf6K/f1AtQ7iPU943S9pyzBCCZSrcoctvFZ4Go1N2y5H8bnMq/h7etoRiwDGuUfD8AkIlA4pOlgQ8ouJWE2PuaqDX4jroFHBob0C6c3hsXot9OPbCAUSVVsUZu/W/xIRUNFiJSTBWwCjkmpAgMBAAECgYBwJ18SsHWtEhmI+OdXgIjQ/J/j4Kn1jjCGdkZgV4NBrMH5TP3sdOSYDMa06TfJyCKlC6nCZ/al8BHlF/+S1VE9Mu8DRrbHAO4OJQyOEaQ64mePL6jYkhVbjr4q7kHTbsIWVu3sH9TJRa3n+lsEpEv90ri458+ofn++h+rlYKlLfQJBAPVWi1VanQlyAtGKmeA7GrxH+XYiqeq4J1suT1qUTsRwEM4RLUZcrsdGio2bVwbbyX3TB2vYdLvf1otdndKBr0MCQQC/Due/BN+B/hqOgMdW2RoHfycg/HVOp7CpsBikRUMegDQGPb6N+z/BIXkVBNHBADzaTcJh0DgSsoMRhlEdTWajAkEAq2V31/yDAytEbtGOqMmB5xG9ZNvYq2NWE2xqAdTkpnXIN75mS+bKL+vHN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c"
;
StringBuilder
sb
=
new
StringBuilder
();
StringBuilder
sb
=
new
StringBuilder
();
for
(
int
i
=
0
;
i
<
50
0
;
i
++)
{
for
(
int
i
=
0
;
i
<
50
;
i
++)
{
sb
.
append
((
char
)
(
'A'
+
i
%
26
));
sb
.
append
((
char
)
(
'A'
+
i
%
26
));
}
}
String
from
=
sb
.
toString
();
String
from
=
sb
.
toString
();
...
...
yzg-util-mq/src/main/java/com/yanzuoguang/mq/service/impl/MqServiceImpl.java
View file @
d47a7fcf
...
@@ -107,7 +107,8 @@ public class MqServiceImpl implements MqService {
...
@@ -107,7 +107,8 @@ public class MqServiceImpl implements MqService {
@Override
@Override
public
void
basicHandle
(
Message
messageBody
,
Channel
channel
,
String
message
,
Consumer
<
String
>
consumerMessage
)
{
public
void
basicHandle
(
Message
messageBody
,
Channel
channel
,
String
message
,
Consumer
<
String
>
consumerMessage
)
{
this
.
basicHandle
(
messageBody
,
channel
,
StringHelper
.
EMPTY
,
StringHelper
.
EMPTY
,
message
,
0
,
consumerMessage
);
String
consumerQueue
=
messageBody
.
getMessageProperties
().
getConsumerQueue
();
this
.
basicHandle
(
messageBody
,
channel
,
consumerQueue
,
consumerQueue
,
message
,
0
,
consumerMessage
);
}
}
@Override
@Override
...
...
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