base 64以角度(2+)编码和解码字符串 [英] base 64 encode and decode a string in angular (2+)

查看:78
本文介绍了base 64以角度(2+)编码和解码字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用base64在angular 2中编码或解码字符串? 我的前端工具是Angular2.我有一个密码字符串,在将其传递给API之前,我需要进行base64编码.由于在服务中,base64编码的字符串将被解码.

How to encode or decode a string in angular 2 with base64 ??? My front-end tool is Angular 2. I had a password string, before passing it to API I need to base64 encode. Since in service base64 encoded string will be decoded.

所以我正在寻找一些用于Angular2/Typescript的base64编码/解码库和一些选项.

So I am looking for some base64 encode/decode library for Angular2/Typescript and some options.

谢谢!

推荐答案

使用 btoa() 函数进行编码:

Use the btoa() function to encode:

console.log(btoa("password")); // cGFzc3dvcmQ=

要进行解码,您可以使用 atob() 函数:

To decode, you can use the atob() function:

console.log(atob("cGFzc3dvcmQ=")); // password

这篇关于base 64以角度(2+)编码和解码字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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