Calculate the digest of an HTTP request.

For all requests that contain a body, the body digest must be calculated and added as a request header named digest, as described in the IETF draft for HTTP digest fields.

In summary, the digest calculation algorithm as used for the Investment API can be applied as follows:

  • Capture the entire request body's byte stream.
  • Calculate the SHA-256 hash of the body content.
  • Encode the resulting value using Base64 encoding
  • Add a request header named digest with this value: SHA-256={digest value}, where {digest value} is replaced by the result of the previous step.

From the above description you should now understand how to calculate a digest. Here are some examples you can use to check your understanding.

Request bodyContent lengthdigest header value
{"hello": "world"}18SHA-256=X48E9qOokqqrvdts8nOJRJN3OWDUoyWxBf7kbu9DBPE=
{"key": "value"}16SHA-256=lyTB4g5uPk1/V+0l+dTvsAblCFkNUoyQ2ll/andcE+U=
0No digest header should be included in the request.

Was this page helpful?