base64 encode and decode a string in angular (2+)

前端 未结 4 1997
被撕碎了的回忆
被撕碎了的回忆 2020-12-04 17:06

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 n

4条回答
  •  自闭症患者
    2020-12-04 17:44

    For encoding to base64 in Angular2, you can use btoa() function.

    Example:-

    console.log(btoa("stringAngular2")); 
    // Output:- c3RyaW5nQW5ndWxhcjI=
    

    For decoding from base64 in Angular2, you can use atob() function.

    Example:-

    console.log(atob("c3RyaW5nQW5ndWxhcjI=")); 
    // Output:- stringAngular2
    

提交回复
热议问题