# Help converting sha256 to 32-bit stream

I need some help with hash value calculation. I am a bit confused by this statement that I found on w3 website on calculation of a DigestValue for xmldsig ( http://www.w3.org/TR/2002/REC-xmlenc-core-20021210/Overview.html#sha256 ):

A SHA-256 digest is a 256-bit string. The content of the DigestValue element shall be the base64 encoding of this bit string viewed as a 32-octet octet stream.

Does that mean that the sha256 hash value has to be converted to a 32-bit string before encoding it to base64? If yes, could someone please tell me how this can be done? I'm a kind of a n00b, but I haven't found info on how to do that on the internet.

• I think this is just a weird formulation for "SHA256 outputs a 32 bytes/256 bits which you should then encode with BASE64". – CodesInChaos Jan 16 '15 at 14:22

So basically they are saying: treat the bit string as a stream of octets of the same length (as $32*8=256$), then base-64 encode it. Now most crypto libraries already treats the output of SHA-256 as byte array (octet stream). So you just are left with encoding the output to base 64.
• Note that the base64 encoding of 32 bytes will be $\lfloor\frac{32}{3}\rfloor\cdot 4 + 4 = 44$ characters, of which the last is an = sign (as we miss one byte when grouping into groups of 3 bytes). – Henno Brandsma Jan 16 '15 at 18:49
• I guess that should be $\lceil\frac{32}{3}\rceil\cdot 4 = 44$ as, for 3 bytes, base64 only uses 4 characters. But that doesn't matter for this result. Thanks for the additional info @HennoBrandsma – Maarten Bodewes Jan 16 '15 at 19:05