PHP - Php & Nodejs Sodium - Compatibility
i've been playing around with nodejs sodium, and im trying to make my js scipt compatable with my php script. Both are using xchacha20poly1305m but the problem is my php encryption looks like this: (whatever it is) ��Bd���||�%��AG�wU�Q��[�V���ȷ&6����_�Y:�q��T��X��e"v�
and my js encrption look like that: Uint8Array {0: 195, 1: 119, 2: 234, 3: 247, 4: 236…}
theres no way of testing the compatability of both scripts when both encodings differ.
here is my php <?php CONST NONCE_LENGTH = SODIUM_CRYPTO_AEAD_XCHACHA20POLY1305_IETF_NPUBBYTES; class Sodium { private $key; public function __construct(string $key) { if (!extension_loaded('sodium')) { throw new Exception('Encryption: PHP Sodium extension not found.'); } $key = trim($key); if (!preg_match('/^[0-9A-Fa-f]{64}+$/', $key)) { throw new Exception('Encryption: Unrecognized key.'); } $this->key = hex2bin($key); } public function encrypt(string $plaintext) { $nonce = random_bytes(NONCE_LENGTH); $ciphertext = sodium_crypto_aead_xchacha20poly1305_ietf_encrypt( $plaintext, null, $nonce, $this->key ); return $nonce . $ciphertext; } public function decrypt(string $encryption) { if (strlen($encryption) < 24) { throw new Exception('Encryption: Unrecognized Encryption.'); } $plaintext = sodium_crypto_aead_xchacha20poly1305_ietf_decrypt( substr($encryption, 24), null, substr($encryption, 0, 24), $this->key ); if ($plaintext === false) { throw new Exception('Encryption: Decryption Failed.'); } return $plaintext; } } $sodium = new Sodium('724b092810ec86d7e35c9d067702b31ef90bc43a7b598626749914d6a3e033ed'); $encryption = $sodium->encrypt('shhh this is a secret'); echo $encryption; echo $sodium->decrypt($encryption);
and you can view the js live here https://codesandbox.io/s/l45orjlnk7 note: when viewing page you may have to delete a character of the code and replace to see results ? or theres a screenshot https://ibb.co/XkcPV4B
i hope you can help with my dilemma
thank you Edited April 14, 2019 by Destramic typo Similar Tutorials<script> //Calculate Labour function filllabour(aa) { //Parse aa var the_string = aa; var parts = the_string.split('-', 2); // After calling split(), 'parts' is an array with two elements: // parts[0] is 'left or -' // parts[1] is 'right of -' var the_text = parts[0]; var the_num = parts[1]; //Parse aa var dblQuantity = document.getElementById('lqlabour-' + the_num).value-0; var curRate = document.getElementById("llabour-" + the_num).value-0; var curRateHelper = document.getElementById("lhelper-" + the_num).value-0; var dblMarkup = document.getElementById("lmarkup-" + the_num).value-0; var curTotal = parseFloat(dblMarkup) / 100.0; llinetotal = ((dblQuantity * curRate) + (dblQuantity * curRateHelper)) * (1 + curTotal); llinetotal = llinetotal.toFixed(2); document.getElementById("ltotal-" + the_num).value = llinetotal; //document.getElementById(the_num).value = ("test"); //alert(the_num); //collect all line totals var inputs = document.getElementsByName("ltotal[]"); var laboursubtotal = 0; for (var i = 0.00; i < inputs.length; i++){ if (inputs[i].type = "text"){ laboursubtotal += parseFloat(inputs[i].value, 10); } } //collect all line totals laboursubtotal = laboursubtotal.toFixed(2); document.getElementById("labourtotal").value = laboursubtotal; filltotal(); } //Calculate Labour </script>hi, in ie11 we are forced to use compatibility mode for one of our web applications written in php. above is a script that from what I understand is the error is with getElementsByName. any suggestions for me in ie11? I use the links in php like this: index.php?content=filename
So I want to use it in future like:
http://example.com/2014/link-name/post-head-name/I dont have the idea how can I do that? Can anybody help me how to do that in PHP? Hi, I have the following code: Code: [Select] <? Header("content-type: application/x-javascript"); function returnimages($dirname="./windows/prezentare_jpg/") { $files = array(); $curimage=0; if($handle = opendir($dirname)) { while(false !== ($file = readdir($handle))){ if(preg_match('/.jpg$/i', $file)){ echo 'galleryarray['.$curimage.']="'.$file .'";'; $curimage++; } } closedir($handle); } return($files); } echo 'var galleryarray=new Array();'; returnimages(); ?> Ran on windows (xampp 1.7.7, PHP 5.3.8, Apache 2.2.21) it returns the correct alfabetical/numerical order: Code: [Select] var galleryarray=new Array();galleryarray[0]="01.jpg";galleryarray[1]="02.jpg";galleryarray[2]="03.jpg";galleryarray[3]="04.jpg";galleryarray[4]="05.jpg";galleryarray[5]="06.jpg";galleryarray[6]="07.jpg";galleryarray[7]="08.jpg";galleryarray[8]="09.jpg";galleryarray[9]="10.jpg";galleryarray[10]="11.jpg";galleryarray[11]="12.jpg"; Ran on linux (PHP 5.3.8, Apache 2.2.21) it returns an incorrect order: Code: [Select] var galleryarray=new Array();galleryarray[0]="06.jpg";galleryarray[1]="01.jpg";galleryarray[2]="08.jpg";galleryarray[3]="10.jpg";galleryarray[4]="04.jpg";galleryarray[5]="11.jpg";galleryarray[6]="05.jpg";galleryarray[7]="03.jpg";galleryarray[8]="07.jpg";galleryarray[9]="09.jpg";galleryarray[10]="02.jpg";galleryarray[11]="12.jpg"; I need the script to run correctly on the linux server. What could be the problem? What can i try? |