Skip to content

Instantly share code, notes, and snippets.

@trustin
Last active December 16, 2015 15:09
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trustin/5453702 to your computer and use it in GitHub Desktop.
Save trustin/5453702 to your computer and use it in GitHub Desktop.
Simple shell script that generates a base64-encoded BitTorrent Sync secret with arbitrary length parameter
#!/bin/bash -e
SECRET_SIZE=128
mkdir -p "$HOME/.local/tmp"
rm -f "$HOME/.local/tmp/btsync-secret".*
umask 0077
SECRET_FILE="`mktemp "$HOME/.local/tmp/btsync-secret.XXXXXXXXXX"`"
echo -n "Generating a $SECRET_SIZE-byte secret "
head --bytes=$SECRET_SIZE /dev/random > "$SECRET_FILE" &
while true; do
CUR_SECRET_SIZE=`stat --format='%s' "$SECRET_FILE"`
if [[ $CUR_SECRET_SIZE -eq $SECRET_SIZE ]]; then
break
fi
sleep 1
echo -n '.'
done
echo ' done'
# Encode first to Base32 and then to Base64 so that resulting secret looks pretty.
SECRET=`cat "$SECRET_FILE" | python -c "import sys;import base64; sys.stdout.write(base64.b32encode(sys.stdin.read()))"`
rm -f "$SECRET_FILE"
SECRET=`echo -n "$SECRET" | sed 's/=\+$//' | base64 -w 0 | sed 's/=\+$//'`
echo $SECRET
@TheBigBear
Copy link

Is there a way to use these longer secrets in mac os x or windows clients? I presume your generated secret is used by the btsync config files you write for linux?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment