[英]JavaScript not correctly encoding and decoding the characters
I have the below code that is decoding incorrectly. 我有以下代码解码错误。
btoa(atob("nirajan")) //Output: "nirajak="
but this below code works perfectly 但这下面的代码完美地工作
btoa(atob("niranjan")) //Output: "niranjan"
Can somebody explain what is wrong with the first part and difference between the two code examples. 有人可以解释一下第一部分有什么问题以及两个代码示例之间的区别。
PS: Tested on Chrome PS:在Chrome上测试
btoa()
encodes the string and atob()
decodes the string. btoa()
对字符串进行编码 ,而atob()
对字符串进行解码 。
So you have your methods backwards. 因此,您的方法将倒退。 First, encode with
btoa
with the inner function, then, decode with atob
on the outer function. 首先,使用内部功能的
btoa
进行编码,然后使用外部功能的atob
进行解码。
atob(btoa('Hello world!')); // returns 'Hello World!'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.