Currently I'm working on project that involves WebSocket technology (Node.js server). And I have a really common problem (there is tons of similar questions on StackOverflow).
My Sec-WebSocket-Accept
is not accepted by browser. And it looks like base64 encoding fails.
Example:
Sec-WebSocket-Key: Hel69aX+iCF5/Js4bATfRw==
Magic number appended: Hel69aX+iCF5/Js4bATfRw==258EAFA5-E914-47DA-95CA-C5AB0DC85B11
SHA-1: b549e61a292a87ce1110b880a0792de41e2d0803
base64: YjU0OWU2MWEyOTJhODdjZTExMTBiODgwYTA3OTJkZTQxZTJkMDgwMw==
Thought my script issues wrong conversion, but this values are being returned by any encoders (base64, sha1) I've tried.
Next I've tried to look some step-by-step Sec-WebSocket-Accept
examples, but their base64 differs from what I get. They are actually much shorter.
For example this one.
base64('e53e4cbf13f58b3e34bcba62de442cfe27c3682a') returns 5T5MvxP1iz40vLpi3kQs/ifDaCo=
in that thread. I've tried browser's btoa('e53e4cbf13f58b3e34bcba62de442cfe27c3682a') and some online base64 encoders, and all of them returns 'ZTUzZTRjYmYxM2Y1OGIzZTM0YmNiYTYyZGU0NDJjZmUyN2MzNjgyYQ=='.
What am I missing?
Thank you!
SOLUTION UPDATE: Question marked as a duplicate as original question explains the reason of my issue. But real solution provided by gre_gor in comments section.