1

I have a (php) array of blowfish encrypted data posted from a form-submit. I have a blowfish algorithm in javascript.

var bf = new Blowfish('12345678901234567');
var ciphertext = bf.encrypt('test data');
alert(ciphertext);
var plaintext = bf.decrypt(ciphertext);
alert(plaintext);

I need to use this javascript blowfish code to decrypt the array of data and save the decrypted data in database.

How can I do this? Can the decrypted value from javascript be assigned to a php variable? Pleas Help...

4
  • Why do you want to encrypt data in javascript? Commented Apr 7, 2011 at 13:08
  • possible duplicate of stackoverflow.com/questions/4747186/… Commented Apr 7, 2011 at 13:08
  • 2
    Exact duplicate stackoverflow.com/search?q=javascript+variable+to+php Commented Apr 7, 2011 at 13:09
  • I think that you're going to need an ajax call but I don't know how to do that in pure javascript. Commented Apr 7, 2011 at 14:31

3 Answers 3

3

PHP is executed server-side (first, it then send the computed HTML etc. to the client), and JavaScript is executed client-side (last).

It would be possible to assign a PHP value to a javascript variable in a PHP file, for example :

<?php
    $myValue = 42;
?>
<script type="text/JavaScript">
    var aVariable = <?=$myValue?>;
</script>

You can't do the opposite (what you asked).

What were you trying to do? Maybe we can help you.

Sign up to request clarification or add additional context in comments.

Comments

1

Dont you just want to use blowfish in PHP? You can use the crypt function for that.

http://php.net/manual/en/function.crypt.php

Comments

0

as TJHeuvel above says you should be capturing the post variables in PHP on the SERVER side not processing with CLIENT side Javascript

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.