简体   繁体   English

如何在HTTP请求标头中发送签名

[英]How to send signature in http request headers

I want send signature in http headers. 我想在http标头中发送签名。 So I have test app that generate signature as byte array and I want print it and insert in request header, but dont know the best way to cast byte array to string and then parse this input string in my filter. 因此,我有一个将签名生成为字节数组的测试应用程序,我想将其打印并插入请求标头中,但不知道将字节数组转换为字符串然后在我的过滤器中解析此输入字符串的最佳方法。

Convert byte[] to String when you send Signature in http header http标头中发送签名时,将byte[]转换为String

byte[] signatures = ...
String signatureAsString = BaseEncoding.base64().encode ( signatures );

To get signature in Http Header in Servlet Filter Servlet过滤器的Http标头中获取签名

// ServletRequest request
HttpServletRequest req = (HttpServletRequest)request;   
String signature = req.getHeader("SIGNATURE");
byte[] bytes = BaseEncoding.base64().decode ( signature  );

I used Google Guava BaseEncoding for encoding/decoding. 我使用Google Guava BaseEncoding进行编码/解码。 You can use any Base64 , Base16 encoding API. 您可以使用任何Base64Base16编码API。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM