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;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user