fix encrypt utils not found, unable to build
This commit is contained in:
+1
-1
@@ -11,7 +11,7 @@ pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
ui/node_modules
|
||||
ui/src/utils/encryptUtils.ts
|
||||
# ui/src/utils/encryptUtils.ts
|
||||
db
|
||||
dist-ssr
|
||||
*.local
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
// utils/encryptUtils
|
||||
const defaultSalt = import.meta.env.VITE_SHARE_KEY_ENCODE_KEY;
|
||||
|
||||
export function encodeKey(text: string, salt: string = defaultSalt): string {
|
||||
const randomLength = Math.floor(Math.random() * 13) + 1; // Random length between 1 and 13
|
||||
const randomPadding = Math.random()
|
||||
.toString(36)
|
||||
.substring(2, 2 + randomLength);
|
||||
const input = randomPadding + salt + text;
|
||||
return btoa(encodeURIComponent(input));
|
||||
}
|
||||
|
||||
export function decodeKey(encoded: string, salt: string = defaultSalt): string {
|
||||
const decoded = decodeURIComponent(atob(encoded));
|
||||
const saltIndex = decoded.indexOf(salt);
|
||||
if (saltIndex === -1) throw new Error("Invalid encoded string or salt");
|
||||
return decoded.slice(saltIndex + salt.length);
|
||||
}
|
||||
Reference in New Issue
Block a user