Welcome Guest, Not a member yet? Register   Sign In
Encryption Passing a Blank PHP Page From Model
#1

I'm very new to Codeigniter. It's only hobby, but I run it on Apache with PHP. I'm getting used to PHP and Codeigniter. My one class was in 2007 and it entailed Access, VBA, Visual Basic and C#. Which should explain the issue ; (I was able to pull a sample MySQL table from a model file to a view file, but seems odd $data going to the view file as nothing.) I eventually want to encrypt all files in the folders and pass them through the model & control folder like containers.

I enabled the ssl extension in PHP. I made a model file that us supposed to be my first go at PHP cryptography. The control seems like it grabs the model file and the view file loads, but nothing. I made the folders red text and file names blue. 

I apologize if it's more a PHP forum topic. 


view folder:
test.php  =
<?php
?>

Model:
Pass1_script.php  =
<?php
class Pass1_script extends CI_Model {
 
function crypt1() { 
$plaintext = "Figure out encryption";
$key = "1234";
$cipher = "aes-128-gcm";
if (in_array($cipher, openssl_get_cipher_methods()))
{
    $ivlen = openssl_cipher_iv_length($cipher);
    $iv = openssl_random_pseudo_bytes($ivlen);
    $ciphertext = openssl_encrypt($plaintext, $cipher, $key, $options=0, $iv, $tag);
 Return('$ciphertext');
  
}
}
}
?>

Control:
practice.php = 
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class practice extends CI_Controller {
 function test() {
  $this->load->model('Pass1_script');
  $data['$ciphertext'] = $this->Pass1_script->crypt1();
  $this->load->view('test', $data);
 }
}
Reply
#2

$data['$ciphertext'] should be $data['ciphertext'].

And in your view: <?php echo $ciphertext; ?>

Encryption are a one way street, so you can't view the original data.
Reply
#3

(11-24-2019, 11:15 AM)jreklund Wrote: $data['$ciphertext'] should be $data['ciphertext'].

And in your view: <?php echo $ciphertext; ?>

Encryption are a one way street, so you can't view the original data.
I appreciate the response. I'll try ['ciphertext' ] in the control. The control file lists $data['$ciphertext'] . It was $ciphertext in the model. Then ('test', $data) in the control folder. I'll make sure to mess with bit64 and the tag once some jumble shows on a test page for decrypting. Seems like the $ acts to pass a string between pages. In Visual Basic, I would have to Dim $anything As String first to pass between pages though. New language whoas, lol

I'll try  the view as:
<?PHP echo $data; ?>

My model query didn't make me put more than <?php    ?>
Reply
#4

I was able to figure out passing the data to the view. In the model folder file, I replaced return('$ciphertext') with echo $ciphertext;..
In my other model example I was returning a value to an echo table. Don't know why return seemed right.

I still appreciate the response. I can now figure out a method to store tag outputs for decryption.
Reply
#5

It should be
Code:
return $ciphertext
as return('$ciphertext') will give you "$ciphertext" and not the actual content.
Reply
#6

Return $ciphertext worked with changing the model to $data['ciphertext'] and the view to <?PHP echo $ciphertext ?>

If I keep the model file to 1 view page, seems more secure to keep the echo in the model for no code on the view?
Reply
#7

(11-26-2019, 02:32 PM)paulywog0667 Wrote: If I keep the model file to 1 view page, seems more secure to keep the echo in the model for no code on the view?

No, not any more secure. And it adds confusion because echo calls should be in views. Some future developer will wonder, "Where is this coming from?" And think poorly of you because you have made their work difficult.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB