|
@@ -1,9 +1,13 @@
|
|
|
export function base64Encode(value: string) {
|
|
export function base64Encode(value: string) {
|
|
|
- return btoa(value).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "")
|
|
|
|
|
|
|
+ const bytes = new TextEncoder().encode(value)
|
|
|
|
|
+ const binary = Array.from(bytes, (b) => String.fromCharCode(b)).join("")
|
|
|
|
|
+ return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "")
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export function base64Decode(value: string) {
|
|
export function base64Decode(value: string) {
|
|
|
- return atob(value.replace(/-/g, "+").replace(/_/g, "/"))
|
|
|
|
|
|
|
+ const binary = atob(value.replace(/-/g, "+").replace(/_/g, "/"))
|
|
|
|
|
+ const bytes = Uint8Array.from(binary, (c) => c.charCodeAt(0))
|
|
|
|
|
+ return new TextDecoder().decode(bytes)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export async function hash(content: string, algorithm = "SHA-256"): Promise<string> {
|
|
export async function hash(content: string, algorithm = "SHA-256"): Promise<string> {
|