python兼容js base64,如何在JavaScript和Python中base64编码unicode字符串?

本文介绍如何使用Base64编码在JavaScript和Python中实现文本加密,确保64字符限制,并能解密回Unicode,以规避中国的Great Firewall。通过Python的base64模块展示了具体操作过程。
摘要由CSDN通过智能技术生成

I need an encript arithmetic, which encript text to text.

the input text could be unicode, and the output should be a-z A-Z 0-9 - . (64 char max)

and it could be decrypt to unicode again.

it should implement in javascript and python.

If there is already some library could do this, great, if there is not, could you tell me.

Let me talk about why

To cheat China Greate Fire Wall , and GAE https has been blocked at china. Angry for this damn goverment.

解决方案

You might want to look at the base64 module. In Python 2.x (starting with 2.4):

>>> import base64

>>> s=u"Rückwärts"

>>> s

u'R\xfcckw\xe4rts'

>>> b=base64.b64encode(s.encode("utf-8"))

>>> b

'UsO8Y2t3w6RydHM='

>>> d=base64.b64decode(b)

>>> d

'R\xc3\xbcckw\xc3\xa4rts'

>>> d.decode("utf-8")

u'R\xfcckw\xe4rts'

>>> print d.decode("utf-8")

Rückwärts

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值