Encryption is a topic that I have literally no experience with whatsoever until I actually learn about it at University next year (excluding basic knowledge of simple cyphers). I'll hopefully understand them better in the future, but for now I'd just llike to implement them into my apps without knowing the inner details.
Scenario
I'm trying to secure one of my PHP/NodeJS apps by adding encryption to it. I'm doing this so I can share data between NodeJS and PHP in a secure manner.
PHP server -> Needs to be able to encrypt and decrypt data
NodeJS server -> Only needs to be able to decrypt data
Possible solutions
I've spent hours searching for a decent solution to my problem. I've tried many code samples, but this seems to be the best code sample that I've come across and tested so far.
As you can see from the code, decryption methods have been built for both NodeJs and PHP. Both appear to work very well so far from what I've tested. That's half of my problem solved already. :-)
What I'm trying to do now, is figure our how to implement an encryption function with PHP code. I've tried this:
print "Encrypted: " . base64_encode(openssl_encrypt("Hello world", 'aes-256-cbc', $password));
but I get the output of: aUZaNnFlWWV5M0dObTE1U3pxMENwdz09
when I should in fact be getting the value of edata as output: U2FsdGVkX18M7K+pELP06c4d5gz7kLM1CcqJBbubW/Q=
Does anyone know why this output is different? I'm obviously doing something wrong, but I just can't figure out what I should be doing as there is so much going on in that PHP code... If someone could give me a little guidance that would be great. Thanks!