Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/extensions/microsoft-authentication/src/browser/buffer.ts
3321 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
export function base64Encode(text: string): string {
7
return btoa(text);
8
}
9
10
export function base64Decode(text: string): string {
11
// modification of https://stackoverflow.com/a/38552302
12
const replacedCharacters = text.replace(/-/g, '+').replace(/_/g, '/');
13
const decodedText = decodeURIComponent(atob(replacedCharacters).split('').map(function (c) {
14
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
15
}).join(''));
16
return decodedText;
17
}
18
19