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

前端 未结 4 2002
被撕碎了的回忆
被撕碎了的回忆 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:55

    Use btoa() for encode and atob() for decode

    text_val:any="your encoding text";
    

    Encoded Text: console.log(btoa(this.text_val)); //eW91ciBlbmNvZGluZyB0ZXh0

    Decoded Text: console.log(atob("eW91ciBlbmNvZGluZyB0ZXh0")); //your encoding text

提交回复
热议问题