Convert Base64 String with Gwt

怎甘沉沦 提交于 2019-12-06 02:41:06

You have two options:

1- Use native JS methods btoa and atob, and convert the returned string to a java byte[] array:

 native String btoa(String b64) /*-{
    return btoa(b64);
 }-*/;
 ...
 byte[] result = btoa(myBase64Data).getBytes();

2- Use a pure java implementation of Base64 algorithm. You can just copy the Base64Utils.java included in the gwt-user.jar, and copy it to your client package, and use its methods:

 import my.project.namespace.client.Base64Utils;
 ...
 byte[] result = Base64Utils.fromBase64(myBase64Data);

Normally I use #1 for IE10, FF and webkit browsers, and #2 for old IE.

Try to use this library https://code.google.com/p/gwt-crypto

It was successful for me.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!