Files
info-target-mobile/constants/crypto.ts
Samandar Turgunboyev 22c1688781 register update
2026-03-18 17:56:26 +05:00

41 lines
1.1 KiB
TypeScript

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;
}
};