Upon looking at Mcrypt_encrypt on the manual, I see that it requires a key. Is there another function or something that allows using a password instead? How would the code look then?
Asked
Active
Viewed 168 times
0
-
2Possible duplicate of [How do you Encrypt and Decrypt a PHP String?](http://stackoverflow.com/questions/16600708/how-do-you-encrypt-and-decrypt-a-php-string) particularly see the *"But I really want to use a password."* section of [this answer](http://stackoverflow.com/a/30159120/1816580). – Artjom B. Oct 27 '15 at 10:48
-
@ArtjomB. Thanks, that's a very helpful post and I will use that method. – Oct 27 '15 at 12:26
-
This is what _key-derivation-functions_ like PBKDF2 are made for, to get a key from a password. – martinstoeckli Oct 27 '15 at 13:40
-
Thanks for that information @martinstoeckli, I'll look into that. I'm new to this encryption stuff. – Oct 27 '15 at 16:37
2 Answers
-1
You ca use crypt
php function as follows. link
<?php
$hashed_password = crypt('mypassword');
?>

Tismon Varghese
- 849
- 1
- 6
- 17
-
1I have to be able to encrypt and decrypt the data. Isn't crypt one-way? I am not wanting to hash a password, I am wanting to create an encryption based on a password. – Oct 27 '15 at 04:13
-
1OP is asking about Password-based Encryption and not "encrypting" a password. – Artjom B. Oct 27 '15 at 10:44
-1
You can try openssl_encrypt() & openssl_decrypt()
and check this answer for a very detailed example.

Community
- 1
- 1

Athi Krishnan
- 159
- 5
-
1If you simply link to another Q&A, then you probably should have commented instead of answering. If they are duplicates, then you should have flagged this question as a duplicate of the question you linked to. – Artjom B. Oct 27 '15 at 10:43
-
@ArtjomB. sorry about that, when i answered this question i didn't have the 'comment everywhere' permission. – Athi Krishnan Oct 27 '15 at 10:50