This commit is contained in:
17
lib/utils/base64.ts
Normal file
17
lib/utils/base64.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
export function base64UrlEncode(buf: Buffer | string) {
|
||||
const s = typeof buf === 'string' ? Buffer.from(buf) : buf
|
||||
|
||||
return s
|
||||
.toString('base64')
|
||||
.replace(/\+/g, '-')
|
||||
.replace(/\//g, '_')
|
||||
.replace(/=+$/, '')
|
||||
}
|
||||
|
||||
export function base64UrlDecode(str: string) {
|
||||
str = str.replace(/-/g, '+').replace(/_/g, '/')
|
||||
|
||||
while (str.length % 4) str += '='
|
||||
|
||||
return Buffer.from(str, 'base64').toString()
|
||||
}
|
||||
Reference in New Issue
Block a user