通过JavaScript Base64URL解码? [英] Base64URL decoding via JavaScript?

查看:263
本文介绍了通过JavaScript Base64URL解码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我很为难。我知道有很多Base64编码的连接codeRS /解codeRS的JS,而不是修改后的(和Facebook惠)Base64URL变化。到目前为止,整个计算器搜索已经拿出晾干。

So I'm stumped. I know there's lots of Base64 encoders/decoders for JS, but not for the modified (and Facebook-favored) Base64URL variation. So far searching across stackoverflow has come up dry.

是的,我可以用PHP或其他服务器端库脱code这一点,但我想保持这种普遍的,无论我用什么平台...例如,如果我主办亚马逊S3 / CloudFront的一个HTML的唯一的Facebook应用程序,并且只使用自己的JS SDK和jQuery照顾加工形式和获取数据。

Yes, I could use PHP or another server-side library to decode this, but I'm trying to keep this universal regardless of what platform I'm using... for example, if I were to host a HTML-only Facebook app on Amazon S3/CloudFront and only use their JS SDK and jQuery to take care of processing forms and getting data.

这是说,没有人知道任何特定的Base64URL德codeRS对JavaScript的?

That said, does anyone know of any Base64URL-specific decoders for JavaScript?

在此先感谢!

推荐答案

解决方案:

var b64str = base64.encode('foo bar');

// fix padding according to the new format
b64str = b64str.padRight(b64str.length + (4 - b64str.length % 4) % 4, '=');

使用这个伟大的base64 EN code /德code:的http://$c$c.google.com/p/stringen$c$crs/source/browse/trunk/javascript/base64.js

还取决于padRight方式:

Also depends on the padRight method:

String.prototype.padRight = function(n, pad){
    t = this;
    if(n > this.length)
        for(i = 0; i < n-this.length; i++)
            t += pad;
    return t;
}

这篇关于通过JavaScript Base64URL解码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆