User Tools

Site Tools


blog:spring2016:cjann:journal

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
blog:spring2016:cjann:journal [2016/04/25 17:48] – [April 22nd 2016] cjannblog:spring2016:cjann:journal [2016/05/02 17:44] (current) – [May 2nd 2016] cjann
Line 670: Line 670:
 ====April 25th 2016==== ====April 25th 2016====
  
 +Openssl_get_ciphermethods is the first openssl type thinger I’ve experimented with. The method is used on line one of the sslex.php file. Apparently, it accesses all available cipher methods. I’ve stored them in a variable, and I’m printing them out using print_r. What we get is a massive array with 164 entries. Das a lot of cipher methds! Most of which I have yet to see anywhere. This really reveals the scope of encryption technology, and the depth of what is out there. I’m finding this topic more interesting as I go along with this research.
 +
 +I’ve noticed that openssl_encrypt takes a parameter called “password”. What is this nonsense about? Research to follow.
 +
 +NOTE: Some of the contributor notes at the bottom have me thinking- would it be possible to encrypt an entire file using php? I have to assume it is possible! How else are files shared between servers and clients securely? This could be an idea for an end of semester project, instead of this research wheel-spinning rut I’m stuck in. I think I’m going to pop smoke on this research paper trail and begin exploring this idea right away. Ho! What about some double encryption action? Could I write php code that encrypts text entered by a user and outputs it into a file, and then some code to encrypt the file? That would be pretty stellar. Side note: from here on out this entry is going to be injected with as much military slang as I can remember from my serving days.
 +
 +Alright, after plugging away for a bit here’s what I have. I’m currently trying to get a string printed out to an existing file using to file_put_contents. When this code attempts to run, I get a permissions error. The same type of error was encountered when I tried to use fopen to create a file when the code is run instead of using a preset file. These methods will be covered later in detail once I get them functioning, but right not I need to eat an apple and get to class.
 +
 +Thanks to Matt and his chmod hooyah, the output works now. chmod 606 was used to change the permissions on the output file to allow write access (along with some awkward command "touch", of which I am completely out of my pay grade) I will continue to plug away and get a functioning prototype before I cover it here. Goals: Successfully encrypt a string, output that string to a file, and encrypt that file using openssl.
 +
 +NOTE: In my most recent iteration / experimentation of my previous encryption work, I was using openssl_random to generate a key for mcrypt. Openssl encryption was under my nose the whole time?!
 +
 +====April 27th 2016====
 +
 +Hunger induced stupor has left me unable to write code very well (forgot my lunch and too busy to hit the cafeteria). So instead of writing code I will document my current progress on my ssl encryption playground. Fun!
 +
 +Open ssl seems a smidge more convenient than the mcrypt method. It uses the previously documented objects as parameters. I was getting a very frustrating error for some of it. It was "Error on line 37: open_sslencrypt() expects parameter 4 to be long, string given in 'filename'". It was particularly frustrating because the message is kind of cryptic. My parameter 4, at the time, was the IV. The IV was the correct length, so the error was really throwing me off.
 +
 +It turns out, I was missing a parameter. I thought one of them was optional, the "options" (haha). The two options are "OPENSSL_RAW_DATA, OPENSSL_ZERO_PADDING", both of which are completely cryptic sounding. Instead, as shown in the example at the top of the page, I used a 0. This apparently satisfies the need for that particular parameter.
 +
 +My initial idea of encrypting text, dumping it into a file, and then encrypting the file may be too ambitious this late in the game. It could have been a potential project had I intercepted this idea earlier, but as it stands the code requires quite a bit of moving parts. I'm afraid that I wouldn't have time to cover everything to aid in understanding. We'll see...
 +
 +I have figured out how to write data into an existing file. The code for creating the file and printing text to the new file doesn't work because of permission functions. Maybe I could morph this into an input / output exercise? (We may have done some I/O stuff earlier in the semester)
 +
 +The current method used for writing to an existing file is actually pretty easy at the basic level, I've been using file_put_contents. It takes only two parameters: the data to be written and the file object.
 +
 +====May 2nd 2016====
 +
 +Well, half of my dream has been realized. I've successfully used openssl encryption to encrypt a string and output it to an existing file. Using all the same output functions previously covered: open_sslencrypt and file_put_contents. As it stands, the new string overtires the old. If one were so inclined there is probably a constant or different method that appends new text after the text that was previously there.
 +
 +Yep, after looking at the documentation there is a parameter constant that can be used to append data to the file instead of overwriting it (the documentation calls it a "flag"). The flags are added after the other parameters (file object and data). The flag used to append data instead of overwriting is FILE_APPEND.
 +
 +Interestingly, file_put_contents is a simplified method to interact with files. A different method would be to use the three functions fopen, fwrite, and fclose. All of these take their own parameters, but it's essentially a longer way to do exactly what file_put_contents does (I think).
 +
 +I did throw down some quick php code in windows to test fopen outside of our unix environment. I wasn't able to use php to create a file because of write permissions. So I whipped up some fast code to create a file with fopen and dump some plain text into it. There must be something more to writing and interpreting php code in windows. When I use the file address in the address bar of a browser all I see is a text version of the file. No output file is created.
 +
 +I did attempt to use the command here http://php.net/manual/en/install.windows.commandline.php
 +To execute the code from the command line. I got the error message "php.exe" is not recognized as an internal or external command, operable program or batch file". So I assume there needs to be some installation required for this command to work. More research to follow.
 +
 +Well obviously there's an installation required. Right above the command to run the file is a link that says "You should read the manual installation steps first!". I've done a great job at ignoring that crucial piece of direction.
 +
 +I'll have to attempt to install required PHP tools when I get home.
 +
 +Also, I may have potentially found a solution to my file permissions issue. There is a PHP function that changes the chmod values of a file! So, potentially, I could use this function to change the permissions of the file I am creating as it is being created. I whipped up some quick code but I can't test it because I forget how to access my files from a browser. I'm super great at this. I'll debug and test the code once I get to class.
blog/spring2016/cjann/journal.1461606538.txt.gz · Last modified: 2016/04/25 17:48 by cjann