kennethToyuan opened a new issue #6080:
URL: https://github.com/apache/apisix/issues/6080


   ### Issue description
   
    public static String HMACSHA256(String data, String key) throws Exception {
           Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
           SecretKeySpec secret_key = new SecretKeySpec(key.getBytes("UTF-8"), 
"HmacSHA256");
           sha256_HMAC.init(secret_key);
           byte[] array = sha256_HMAC.doFinal(data.getBytes("UTF-8"));
           StringBuilder sb = new StringBuilder();
           for (byte item : array) {
               sb.append(Integer.toHexString((item & 0xFF) | 
0x100).substring(1, 3));
           }
           return sb.toString().toUpperCase();
       }
   
   String 
message=HMACSHA256("GET\n/index.html\nage=36&name=james\nuser-key\nTue, 19 Jan 
2021 11:33:20 GMT\nUser-Agent:curl/7.29.0\nx-custom-a:test\n","my-secret-key")
   
    String base64encodedString = 
java.util.Base64.getEncoder().encodeToString(message.getBytes("utf-8"));
    
   System.out.println(base64encodedString ); 
   
   out:
   
RDIwQTBCOTdBMERDQzBGNzAwODg4OTNERDY5QTIyRTcwRDYxODg2RTlFOTA4QzhERTg2QTlDOTZDRTE3QkFGMA==
   
   official generated:
   8XV1GB7Tq23OJcoz6wjqTs4ZLxr9DiLoY4PxzScWGYg=
   
   Incorrect length and value does not match,why??
   
   ### Environment
   
   - apisix version (cmd: `apisix version`):
   - OS (cmd: `uname -a`):
   - OpenResty / Nginx version (cmd: `nginx -V` or `openresty -V`):
   - etcd version, if have (cmd: run `curl 
http://127.0.0.1:9090/v1/server_info` to get the info from server-info API):
   - apisix-dashboard version, if have:
   - the plugin runner version, if the issue is about a plugin runner (cmd: 
depended on the kind of runner):
   - luarocks version, if the issue is about installation (cmd: `luarocks 
--version`):
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to