Created
January 5, 2017 03:41
-
-
Save allaniftrue/95f2aa71c8e842a8fcb82c562ed61641 to your computer and use it in GitHub Desktop.
Encrypting a password with a self-signed certificate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * | |
| * @param $password A user defined password | |
| * @return string | |
| * | |
| */ | |
| public function encryptPasswordToRsaBase64(string $password): string | |
| { | |
| $publicKey = fopen('/path/to/public/key.pem', 'r'); | |
| $publicKeyString = fread($publicKey, 8192); | |
| fclose($publicKey); | |
| openssl_get_publickey($publicKeyString); | |
| openssl_public_encrypt($password, $encryptedPin, $publicKeyString); | |
| return (string) base64_encode($encryptedPin); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment