Calculate the content-digest of an HTTP request.

For all requests that contain a body, the content digest of the body must be calculated and added as a request header named content-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-512 hash of the body content.
  • Encode the resulting value using Base64 encoding
  • Add a request header named content-digest with this value: sha-512=:{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 lengthcontent-digest header value
{"hello": "world"}18sha-512=:WZDPaVn/7XgHaAy8pmojAkGWoRx2UFChF41A2svX+TaPm+AbwAgBWnrIiYllu7BNNyealdVLvRwEmTHWXvJwew==:
{"key": "value"}16sha-512=:Hd9/AvGZkbjitW1+Ml8Fg1ux1mtcDYe6mLQjDyoowIWa3LM/PmwN2v9O+MjtQGrCA3EQWUL54dlgxKHyYbrucw==:
0No content-digest header should be included in the request.

Was this page helpful?