Robust AngularJS Base64 encoder