I need to write websocket server on GAWK. And server must handle user's Sec-WebSocket-Key by following algorithm (from RFC):Concat key with 258EAFA5-E914-47DA-95CA-C5AB0DC85B11Take sha-1 in binary form (should have 20 symbols)Take base64 from that binary formI'm trying to use openssl but the resulting code is incorrect:$ openssl sha1 -binary <<< 'a0+ZvgYqsMFHRerif0go8g==258EAFA5-E914-47DA-95CA-C5AB0DC85B11' | openssl base64mYryklMdRrrLwrMQDeKEzOVMMWk=Meanwhile, the following PHP code generates valid output:$key = a0+ZvgYqsMFHRerif0go8g==;$hash = $key.'258EAFA5-E914-47DA-95CA-C5AB0DC85B11'; $hash = sha1($hash,true);$hash = base64_encode($hash); echo($hash);tswGtNOxrRhDmC04XQaDigMeaJA=What am I doing wrong?
Openssl generate invalid websocket security code
shell;hashsum;here string
The here string construct <<< feeds the given string plus a newline as input to the command. So openssl sha1 -binary <<< 'a0+ZvgYqsMFHRerif0go8g==258EAFA5-E914-47DA-95CA-C5AB0DC85B11' is equivalent toprintf '%s\n' 'a0+ZvgYqsMFHRerif0go8g==258EAFA5-E914-47DA-95CA-C5AB0DC85B11' | openssl sha1 -binaryBut your specification says Concat key with 258EAFA5-E914-47DA-95CA-C5AB0DC85B11, not Concat[enate the] key with 258EAFA5-E914-47DA-95CA-C5AB0DC85B11 and a newline. So you needprintf '%s' 'a0+ZvgYqsMFHRerif0go8g==258EAFA5-E914-47DA-95CA-C5AB0DC85B11' | openssl sha1 -binaryand this does produce tswGtNOxrRhDmC04XQaDigMeaJA=.echo -n  is equivalent to printf %s  except that there are shells that don't support echo -n or that expand backslash escapes in echo , whereas printf %s  has a standard behavior (always print the argument literally).