File tree Expand file tree Collapse file tree 1 file changed +14
-3
lines changed
src/main/java/org/javawebstack/framework/util Expand file tree Collapse file tree 1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change 77import javax .crypto .*;
88import javax .crypto .spec .IvParameterSpec ;
99import javax .crypto .spec .SecretKeySpec ;
10+ import java .io .UnsupportedEncodingException ;
1011import java .nio .charset .StandardCharsets ;
1112import java .security .InvalidAlgorithmParameterException ;
1213import java .security .InvalidKeyException ;
@@ -48,11 +49,21 @@ public boolean check(String hash, String data) {
4849 }
4950
5051 public String sign (String data ) {
51- return hash ( new String ( this . key ) + data );
52+ return sign ( data . getBytes ( StandardCharsets . UTF_8 ) );
5253 }
5354
54- public boolean checkSignature (String data , String signature ) {
55- return check (signature , new String (this .key ) + data );
55+ public String sign (byte [] data ) {
56+ Mac sha512Hmac ;
57+ try {
58+ sha512Hmac = Mac .getInstance ("HmacSHA512" );
59+ SecretKeySpec keySpec = new SecretKeySpec (key , "HmacSHA512" );
60+ sha512Hmac .init (keySpec );
61+ byte [] macData = sha512Hmac .doFinal (data );
62+ return new String (Base64 .getEncoder ().encode (macData ), StandardCharsets .UTF_8 );
63+ } catch (InvalidKeyException | NoSuchAlgorithmException e ) {
64+ e .printStackTrace ();
65+ return null ;
66+ }
5667 }
5768
5869 public String encryptLaravel (String data ) {
You can’t perform that action at this time.
0 commit comments