diff --git a/http.c b/http.c index 88222a5..2cbcdec 100644 --- a/http.c +++ b/http.c @@ -43,9 +43,9 @@ d_char *http_signed_request(snac *snac, char *method, char *url, /* digest */ if (body != NULL) - digest = xs_sha256_hex(body, b_size); + digest = xs_sha256_base64(body, b_size); else - digest = xs_sha256_hex("", 0); + digest = xs_sha256_base64("", 0); seckey = xs_dict_get(snac->key, "secret"); diff --git a/xs_openssl.h b/xs_openssl.h index a6a17b1..43a18e1 100644 --- a/xs_openssl.h +++ b/xs_openssl.h @@ -7,6 +7,7 @@ d_char *xs_md5_hex(const void *input, int size); d_char *xs_sha1_hex(const void *input, int size); d_char *xs_sha256_hex(const void *input, int size); +d_char *xs_sha256_base64(const void *input, int size); d_char *xs_rsa_genkey(int bits); d_char *xs_rsa_sign(char *secret, char *mem, int size); int xs_rsa_verify(char *pubkey, char *mem, int size, char *b64sig); @@ -45,19 +46,38 @@ d_char *xs_sha1_hex(const void *input, int size) } -d_char *xs_sha256_hex(const void *input, int size) +unsigned char *_xs_sha256(const void *input, int size, unsigned char *sha256) { - unsigned char sha256[32]; SHA256_CTX ctx; SHA256_Init(&ctx); SHA256_Update(&ctx, input, size); SHA256_Final(sha256, &ctx); + return sha256; +} + + +d_char *xs_sha256_hex(const void *input, int size) +{ + unsigned char sha256[32]; + + _xs_sha256(input, size, sha256); + return xs_hex_enc((char *)sha256, sizeof(sha256)); } +d_char *xs_sha256_base64(const void *input, int size) +{ + unsigned char sha256[32]; + + _xs_sha256(input, size, sha256); + + return xs_base64_enc((char *)sha256, sizeof(sha256)); +} + + d_char *xs_rsa_genkey(int bits) /* generates an RSA keypair */ {