🕵️ SicherheitslückenHak5: Hackers Just Poisoned the Rust Supply Chain | Threat Wire(01.09.2026 um 14:00 Uhr)
🕵️ SicherheitslückenHak5: Hackers Found a Way Into Humanoid Robots | Threat Wire(04.09.2026 um 15:04 Uhr)
🔧 AI Nachrichten Bits und so #1021 (Passwort für Laufwerk)(31.08.2026 um 22:15 Uhr)
🔧 AI Nachrichten Bits und so #1022 (Wie Weißbier)(06.09.2026 um 20:39 Uhr)
🍏 iOS / Mac OSHue-App 6.0 ist da: das sind die Neuerungen(07.09.2026 um 17:21 Uhr)
🕵️ SicherheitslückenHak5: Hackers Just Poisoned the Rust Supply Chain | Threat Wire(01.09.2026 um 14:00 Uhr)
🕵️ SicherheitslückenHak5: Hackers Found a Way Into Humanoid Robots | Threat Wire(04.09.2026 um 15:04 Uhr)
🔧 AI Nachrichten Bits und so #1021 (Passwort für Laufwerk)(31.08.2026 um 22:15 Uhr)
🔧 AI Nachrichten Bits und so #1022 (Wie Weißbier)(06.09.2026 um 20:39 Uhr)
🍏 iOS / Mac OSHue-App 6.0 ist da: das sind die Neuerungen(07.09.2026 um 17:21 Uhr)

🔧 Programmierung 🕛 kürzlich 3 Min Lesezeit
0

Create Encryption and Decryption function using npm CryptoJS

↗ Quelle (dev.to)
🗣️ Stimme:

CODE
const CryptoJS = require('crypto-js');

function randomString(length) {
var text = '';

var possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';

for (var i = 0; i < length; i++) {
text += possible.charAt(Math.floor(Math.random() * possible.length));
}

// var key = text + navigator.sayswho + $(window).width();

var key = text;

return key;
}



exports.CareerDecrypt = async cipherData => {
if (process.env.ENABLE_ENCERIPTION == 0) return cipherData;
console.log('cipherData', cipherData);
if (!cipherData) {
console.log('cipherData', cipherData);
throw Error('somthing went wrong !!');
}

var key = CryptoJS.enc.Utf8.parse('$k@m0u$0172@0r!k$k@m0u$0172@0r!k');
var iv = CryptoJS.enc.Utf8.parse(cipherData.slice(cipherData.length - 16));
cipherData = cipherData.slice(0, cipherData.length - 16);
var decrypted = CryptoJS.AES.decrypt(cipherData, key, {
iv: iv,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7,
});
// console.log("here",decrypted.toString(CryptoJS.enc.Utf8))
let Jsondata = JSON.parse(`${decrypted.toString(CryptoJS.enc.Utf8)}`);

return Jsondata;
};

exports.CareerEncrypt = plain => {
if (process.env.ENABLE_ENCERIPTION == 1) {
let randomIV = randomString(16);
var key = CryptoJS.enc.Utf8.parse('$k@m0u$0172@0r!k$k@m0u$0172@0r!k');
var iv = CryptoJS.enc.Utf8.parse(randomIV);
// var iv = CryptoJS.enc.Utf8.parse("@1O2j3D4e5F6g7P8");
// console.log(iv, randomIV);
var encrypted = CryptoJS.AES.encrypt(JSON.stringify(plain), key, {
iv: iv,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7,
});

let encrypt = encrypted.toString() + randomIV;
console.log(encrypt.replace(/\\/g, '/'));
return encrypt.replace(/\\/g, '/');
} else {
console.log('err');
return plain;
}

// return encrypted.toString();
};

exports.CareerEncryptold = async plain => {
if (process.env.ENABLE_ENCERIPTION == 1) {
let randomIV = randomString(16);
var key = CryptoJS.enc.Utf8.parse('$k@m0u$0172@0r!k');
var iv = CryptoJS.enc.Utf8.parse(randomIV);
var encrypted = CryptoJS.AES.encrypt(JSON.stringify(plain), key, {
keySize: 128 / 8,
iv: iv,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7,
});

let encrypt = encrypted.toString() + randomIV;
return encrypt.replace(/\\/g, '/');
} else {
return plain;
}

// return encrypted.toString();
};

exports.eSettlementEncrypt = async plainText => {
try {
// Define the encryption key and initialization vector (IV)
const secretKey = CryptoJS.enc.Utf8.parse('8080808080808080');
const iv = CryptoJS.enc.Utf8.parse('8080808080808080');

// Encrypt the plain text
const encrypted = CryptoJS.AES.encrypt(JSON.stringify(plainText), secretKey, {
keySize: 128 / 8,
iv: iv,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7,
});

// Return the encrypted string
const encryptedString = encrypted.toString();
console.log('Encrypted Text:', encryptedString);
return encryptedString;
} catch (error) {
console.error('Encryption Error:', error.message);
throw new Error('Encryption failed');
}
};

exports.eSettlementDecrypt = async cipherData => {
try {
if (!cipherData) {
console.log('cipherData is missing:', cipherData);
throw new Error('Decryption failed: cipherData is required.');
}

// Define the decryption key and initialization vector (IV)
const secretKey = CryptoJS.enc.Utf8.parse('8080808080808080');
const iv = CryptoJS.enc.Utf8.parse('8080808080808080');

// Decrypt the cipher text
const decrypted = CryptoJS.AES.decrypt(cipherData, secretKey, {
keySize: 128 / 8,
iv: iv,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7,
});

// Convert the decrypted data back to UTF-8 and parse JSON
const decryptedText = decrypted.toString(CryptoJS.enc.Utf8);
const jsonData = JSON.parse(decryptedText);

return jsonData;
} catch (error) {
console.error('Decryption Error:', error.message);
throw new Error('Decryption failed');
}
};


Vollständiger Original-Bericht
Ausführliche Details, Code-Beispiele & Hersteller-Stellungnahme auf dev.to.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
Hackers Just Poisoned the Rust Supply Chain | Threat Wire
1 Quelle
Hackers Found a Way Into Humanoid Robots | Threat Wire
1 Quelle
Bits und so #1021 (Passwort für Laufwerk)
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Create Encryption and Decryption function using npm CryptoJS

Thematisch verwandte Begriffe: Create, Encryption, Decryption, function · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...