0

is there a base64 library in angular2,i want to encode a token in base64:

getHeader(token:string) {
    let headers = new Headers();

    headers.append("Content-Type", "application/json");
    headers.append("Authorization", "Basic " + token);

    let options = new RequestOptions({ headers: headers });
    return options;
 }
  • 3
    Possible duplicate of [How can you encode a string to Base64 in JavaScript?](http://stackoverflow.com/questions/246801/how-can-you-encode-a-string-to-base64-in-javascript) – Igor Jan 31 '17 at 16:37

1 Answers1

0

yes its really easy use btoa() :

let encodedPassword:string = btoa(password);

then you can use it for decoding you can use atob:

let decodedPassword:string = atob(password);