bearhunterUA
bearhunterUA

Reputation: 259

How to send signature in http request headers

I want send signature in http headers. 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.

Upvotes: 1

Views: 3773

Answers (1)

LHA
LHA

Reputation: 9655

Convert byte[] to String when you send Signature in http header

byte[] signatures = ...
String signatureAsString = BaseEncoding.base64().encode ( signatures );
// Add signatureAsString as a HTTP header X-SIGN

To get signature in Http Header in Servlet Filter

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

I used Google Guava BaseEncoding for encoding/decoding. You can use any Base64, Base16 encoding API.

Upvotes: 3

Related Questions