register update
This commit is contained in:
41
constants/crypto.ts
Normal file
41
constants/crypto.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import CryptoJS from 'crypto-js';
|
||||
|
||||
/**
|
||||
* Backenddan kelgan shifrlangan tokenni ochish
|
||||
*/
|
||||
export const decryptToken = (encryptedBase64: string) => {
|
||||
try {
|
||||
// 1. Base64 dan WordArray ga
|
||||
const encryptedData = CryptoJS.enc.Base64.parse(encryptedBase64);
|
||||
|
||||
// 2. IV (dastlabki 16 bayt)
|
||||
const iv = CryptoJS.lib.WordArray.create(encryptedData.words.slice(0, 4));
|
||||
|
||||
// 3. Ciphertext (qolgan qism)
|
||||
const ciphertext = CryptoJS.lib.WordArray.create(
|
||||
encryptedData.words.slice(4),
|
||||
encryptedData.sigBytes - 16
|
||||
);
|
||||
|
||||
// 4. Maxfiy kalit
|
||||
const key = CryptoJS.enc.Utf8.parse("12345678901234567890123456789012");
|
||||
|
||||
// 5. CipherParams yaratish
|
||||
const cipherParams = CryptoJS.lib.CipherParams.create({
|
||||
ciphertext,
|
||||
key,
|
||||
iv
|
||||
});
|
||||
|
||||
// 6. Dekodlash
|
||||
const decrypted = CryptoJS.AES.decrypt(cipherParams, key, {
|
||||
iv,
|
||||
mode: CryptoJS.mode.CBC,
|
||||
padding: CryptoJS.pad.Pkcs7
|
||||
});
|
||||
|
||||
return decrypted.toString(CryptoJS.enc.Utf8);
|
||||
} catch (error) {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
55
constants/formatText.ts
Normal file
55
constants/formatText.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
const latinToCyrillicMap = [
|
||||
["O'", "Ў"], ["o'", "ў"],
|
||||
["G'", "Ғ"], ["g'", "ғ"],
|
||||
["Sh", "Ш"], ["sh", "ш"],
|
||||
["Ch", "Ч"], ["ch", "ч"],
|
||||
["A", "А"], ["B", "Б"], ["D", "Д"], ["E", "Е"], ["F", "Ф"],
|
||||
["G", "Г"], ["H", "Ҳ"], ["I", "И"], ["J", "Ж"], ["K", "К"],
|
||||
["L", "Л"], ["M", "М"], ["N", "Н"], ["O", "О"], ["P", "П"],
|
||||
["Q", "Қ"], ["R", "Р"], ["S", "С"], ["T", "Т"], ["U", "У"],
|
||||
["V", "В"], ["X", "Х"], ["Y", "Й"], ["Z", "З"],
|
||||
["a", "а"], ["b", "б"], ["d", "д"], ["e", "е"], ["f", "ф"],
|
||||
["g", "г"], ["h", "ҳ"], ["i", "и"], ["j", "ж"], ["k", "к"],
|
||||
["l", "л"], ["m", "м"], ["n", "н"], ["o", "о"], ["p", "п"],
|
||||
["q", "қ"], ["r", "р"], ["s", "с"], ["t", "т"], ["u", "у"],
|
||||
["v", "в"], ["x", "х"], ["y", "й"], ["z", "з"],
|
||||
["'", ""] // apostrofni olib tashlaymiz
|
||||
];
|
||||
|
||||
export function formatText(str: string | null) {
|
||||
if (!str) return null;
|
||||
let result = str;
|
||||
for (let [latin, cyrillic] of latinToCyrillicMap) {
|
||||
const regex = new RegExp(latin, "g");
|
||||
result = result.replace(regex, cyrillic);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
const cyrillicToLatinMap = [
|
||||
["Ў", "O'"], ["ў", "o'"],
|
||||
["Ғ", "G'"], ["ғ", "g'"],
|
||||
["Ш", "Sh"], ["ш", "sh"],
|
||||
["Ч", "Ch"], ["ч", "ch"],
|
||||
["ё", "yo"], ["Ё", "YO"],
|
||||
["А", "A"], ["Б", "B"], ["Д", "D"], ["Е", "E"], ["Ф", "F"],
|
||||
["Г", "G"], ["Ҳ", "H"], ["И", "I"], ["Ж", "J"], ["К", "K"],
|
||||
["Л", "L"], ["М", "M"], ["Н", "N"], ["О", "O"], ["П", "P"],
|
||||
["Қ", "Q"], ["Р", "R"], ["С", "S"], ["Т", "T"], ["У", "U"],
|
||||
["В", "V"], ["Х", "X"], ["Й", "Y"], ["З", "Z"],
|
||||
["а", "a"], ["б", "b"], ["д", "d"], ["е", "e"], ["ф", "f"],
|
||||
["г", "g"], ["ҳ", "h"], ["и", "i"], ["ж", "j"], ["к", "k"],
|
||||
["л", "l"], ["м", "m"], ["н", "n"], ["о", "o"], ["п", "p"],
|
||||
["қ", "q"], ["р", "r"], ["с", "s"], ["т", "t"], ["у", "u"],
|
||||
["в", "v"], ["х", "x"], ["й", "y"], ["з", "z"],
|
||||
];
|
||||
|
||||
export function formatTextToLatin(str: string | null) {
|
||||
if (!str) return null;
|
||||
let result = str;
|
||||
for (let [cyrillic, latin] of cyrillicToLatinMap) {
|
||||
const regex = new RegExp(cyrillic, "g");
|
||||
result = result.replace(regex, latin);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
Reference in New Issue
Block a user