Skip to content

Instantly share code, notes, and snippets.

@allaniftrue
Created January 5, 2017 03:41
Show Gist options
  • Select an option

  • Save allaniftrue/95f2aa71c8e842a8fcb82c562ed61641 to your computer and use it in GitHub Desktop.

Select an option

Save allaniftrue/95f2aa71c8e842a8fcb82c562ed61641 to your computer and use it in GitHub Desktop.
Encrypting a password with a self-signed certificate
<?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