How to encode/decode to base64?

466 views
Skip to first unread message

Ivan Zaera Avellon

unread,
Feb 2, 2014, 1:57:22 PM2/2/14
to mi...@dartlang.org
Hi list:

I've seen that crypto.dart has been moved to dart:io and CryptoUtils has been made private. So now, what do we need to use to encode/decode to base64? I've done a search through the whole SDK and I can't see anything to do that.

Also, there's this package:

http://pub.dartlang.org/packages/base64_codec

But it is obsolete and doesn't "compile" with latest versions of the SDK (I copy/pasted it and fixing it is a matter of changing two lines, but the fact is that it seems to be deprecated).

Any hint on this?

Thanks,
Ivan

signature.asc
Message has been deleted

Ross Smith

unread,
Feb 2, 2014, 2:27:22 PM2/2/14
to mi...@dartlang.org
Hey Ivan,

I was looking for this the past week also and it was tough to find.  It seems like a good candidate for `dart:convert` since it is so common?  Note that if you have a dependency on `dart:html` (which you probably don't I'm guessing) you can use `window.btoa` and `window.atob`.  They have no dartdoc, but this is what they do :)


cheers

Ivan Zaera Avellon

unread,
Feb 2, 2014, 2:49:56 PM2/2/14
to mi...@dartlang.org
Thanks!

I passed by and saw that class but never thought that it could do the base64 stuff. I'll use it since now I'm programming for the client side, but that won't be available in the server :-(.

I too think that it should be supported in the SDK (or at least in a maintained package). In fact, googling for it, I've seen that many people seem to have removed base64 code from their projects when it was made available in CryptoUtils.

BTW: looking at github's history I've seen this:

=============
https://github.com/dart-lang/bleeding_edge/commit/213c00cd99f142d0be321d7db2f7d6a206f701be

Remove the dart:io dependency on dart:crypto
In preparation to move dart:crypto to a package.
=============

So I guess that's the reason. The bad news is that the commit is 8 months old!

And the good news is that crypto is in pub already: http://pub.dartlang.org/packages/crypto

So I'll use that instead of Window :-).


Cheers.


El 02/02/14 20:27, Ross Smith escribió:
> Hey Ivan,
>
> I was looking for this the past week also and it was tough to find. It seems like a good candidate for `dart:convert` since it is so common? Note that if you have a dependency on `dart:html` (which you probably don't I'm guessing) you can use `window.btoa` and `window.atob`. They have no dartdoc, but this is what they do :)
>
> https://api.dartlang.org/docs/channels/dev/latest/dart_html/Window.html#atob
>
> cheers
>
> On Sunday, February 2, 2014 8:57:22 PM UTC+2, Iván Zaera Avellón wrote:
>
> Hi list:
>
> I've seen that crypto.dart has been moved to dart:io and CryptoUtils has been made private. So now, what do we need to use to encode/decode to base64? I've done a search through the whole SDK and I can't see anything to do that.
>
> Also, there's this package:
>
> http://pub.dartlang.org/packages/base64_codec <http://pub.dartlang.org/packages/base64_codec>
>
> But it is obsolete and doesn't "compile" with latest versions of the SDK (I copy/pasted it and fixing it is a matter of changing two lines, but the fact is that it seems to be deprecated).
>
> Any hint on this?
>
> Thanks,
> Ivan
>
> --
> For other discussions, see https://groups.google.com/a/dartlang.org/
>
> For HOWTO questions, visit http://stackoverflow.com/tags/dart
>
> To file a bug report or feature request, go to http://www.dartbug.com/new
>
> To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.

signature.asc

Ivan Zaera Avellon

unread,
Feb 2, 2014, 2:54:47 PM2/2/14
to mi...@dartlang.org
My fault. It's there. I searched for it twice and didn't see it :-(. I'm getting old...

I was misleaded by the crypto.dart inside dart:io. I should have searched for it with the easy method instead of browsing around and making things difficult :-D.


El 02/02/14 20:09, Ahmet A. Akın escribió:
> Have you searched dartlang api page for Base64?
>

signature.asc

Ross Smith

unread,
Feb 3, 2014, 3:01:40 AM2/3/14
to mi...@dartlang.org
If you are in the browser I would expect the window methods to outperform a pub package, as they are implemented by the browser.  But be careful if you have Unicode.

A codec in `dart:covert` would be nice as it could do the optimal thing in each environment, and take care of the Unicode issue.  Probably using typed data in Dartium / vm and falling back to encodeUriComponent -> unescape -> btoa in other browsers.

cheers

Ross Smith

unread,
Feb 3, 2014, 3:09:23 AM2/3/14
to mi...@dartlang.org
Whoops I meant `dart:convert`. I don't think they are ready to announce `dart:covert` just yet :)
Reply all
Reply to author
Forward
0 new messages