“Verschlüsseln in PHP OpenSSL und Entschlüsselung in JavaScript -Cryptojs” Code-Antworten

Verschlüsseln in PHP OpenSSL und Entschlüsselung in JavaScript -Cryptojs

function CryptoJSAesDecrypt(passphrase,encrypted_json_string){

    var obj_json = JSON.parse(encrypted_json_string);

    var encrypted = obj_json.ciphertext;
    var salt = CryptoJS.enc.Hex.parse(obj_json.salt);
    var iv = CryptoJS.enc.Hex.parse(obj_json.iv);   

    var key = CryptoJS.PBKDF2(passphrase, salt, { hasher: CryptoJS.algo.SHA512, keySize: 64/8, iterations: 999});


    var decrypted = CryptoJS.AES.decrypt(encrypted, key, { iv: iv});

    return decrypted.toString(CryptoJS.enc.Utf8);
}

console.log(CryptoJSAesDecrypt('your passphrase','<?php echo $string_json_fromPHP?>'));
Australian Spiny Anteater

Verschlüsseln in PHP OpenSSL und Entschlüsselung in JavaScript -Cryptojs

function CryptoJSAesEncrypt($passphrase, $plain_text){

    $salt = openssl_random_pseudo_bytes(256);
    $iv = openssl_random_pseudo_bytes(16);
    //on PHP7 can use random_bytes() istead openssl_random_pseudo_bytes()
    //or PHP5x see : https://github.com/paragonie/random_compat

    $iterations = 999;  
    $key = hash_pbkdf2("sha512", $passphrase, $salt, $iterations, 64);

    $encrypted_data = openssl_encrypt($plain_text, 'aes-256-cbc', hex2bin($key), OPENSSL_RAW_DATA, $iv);

    $data = array("ciphertext" => base64_encode($encrypted_data), "iv" => bin2hex($iv), "salt" => bin2hex($salt));
    return json_encode($data);
}

$string_json_fromPHP = CryptoJSAesEncrypt("your passphrase", "your plain text");
Australian Spiny Anteater

Verschlüsseln in PHP OpenSSL und Entschlüsselung in JavaScript -Cryptojs

���*��S��ȝ{9_Q��R��x�#�6�	QX�7���

            		

PHP answers related to “Encrypt in PHP openssl and decrypt in javascript CryptoJS”


PHP queries related to “Encrypt in PHP openssl and decrypt in javascript CryptoJS”




Browse PHP Answers by Framework


More “Kinda” Related PHP Answers View All PHP Answers »

Smoggy Stork

Ähnliche Antworten wie “Verschlüsseln in PHP OpenSSL und Entschlüsselung in JavaScript -Cryptojs”

Fragen ähnlich wie “Verschlüsseln in PHP OpenSSL und Entschlüsselung in JavaScript -Cryptojs”

Weitere verwandte Antworten zu “Verschlüsseln in PHP OpenSSL und Entschlüsselung in JavaScript -Cryptojs” auf PHP

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen