0

How to use Decrypt Function on value (k,v) of jquery I have tried many things. But it's still hasn't Please give advice.

function query_user (No) {
    var text = '';        
    $.ajaxSetup({
        async: false
    });
    $.ajax('controller/query_user.php', {
        type: 'POST',
        data: {
            'Id': No
        },
        dataType: 'json',
        success: function(data2) {
            $.each(data2,function(k,v){
                $("#Name").val(v.Name);
                $("#LastName").val(v.LastName);
                $("#add_id").attr("href","test.php?Id="+v.Id);
                $("#Id").val(v.Id);
            });
        }
    });
}

decrypt function

function decrypt($data, $key) {
    $encryption_key = base64_decode($key);
    list($encrypted_data, $iv) = array_pad(explode(':::', base64_decode($data), 3),3,null);
   return openssl_decrypt($encrypted_data, 'aes-256-cbc', $encryption_key, 0, $iv);
}

my key

$key = "1212312121";

I would like to provide the source data to be decrypted

<div class="col-md-2"><label for="Name">Name</label><input type="text" id="Name" name="Name" class="form-control"  value = "" readonly/></div>
<div class="col-md-2"><label for="LastName">LastName</label><input type="text" id="LastName" name="LastName" class="form-control" value="" readonly/></div>

My Data column

Name = cHV6Rno3VnlTYU5VTzk1clQ3bi8wQT09OjphbXPN2GTwGJykqq0xIemc Lastname =OWpJbXBOWU1TNjZ4cGNYNWhuUUNmYXY1NjRQQzR6T3ZUWUZWc1o4ano5Y3hYTkx6TTZyZVQwd1NnKzRwVy9nbDo6pn8zI1mtQckWAmG+nbYv0w==

I want to decrypt "name" and "lastname" using Decrypt function because now I'm using JQUERY but it only shows encrypted data.

  • Does this answer your question? [Encrypt in PHP openssl and decrypt in javascript CryptoJS](https://stackoverflow.com/questions/41222162/encrypt-in-php-openssl-and-decrypt-in-javascript-cryptojs) – Nico Haase Jul 22 '21 at 09:12
  • If not, please share more details. Where do you try to decrypt anything in the given JS code? – Nico Haase Jul 22 '21 at 09:13
  • the name is already encrypted but i can't decrypted value – Beginner Programmer Jul 22 '21 at 09:26
  • Please share more details. What have you tried to decrypt anything using jQuery? – Nico Haase Jul 22 '21 at 09:32
  • Where does this "data column" come from? What have you tried to decrypt it using jQuery? – Nico Haase Jul 22 '21 at 10:15
  • If you decrypt on the client-side with jquery you will have to expose your key and then anybody can decrypt it. You will have to make a new route for decryption and send your data back and forward or decrypt before you send it to the client. – E P Jul 22 '21 at 13:42

0 Answers0