Created
January 28, 2016 22:55
-
-
Save aaronranard/62aed8148395deafed71 to your computer and use it in GitHub Desktop.
PHP: PHPECC
This file contains 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 | |
$loader = new PemLoader(); | |
$math = EccFactory::getAdapter(); | |
$this->messages = new MessageFactory($math); | |
$privKeySerializer = new PemPrivateKeySerializer(new DerPrivateKeySerializer()); | |
$pubKeySerializer = new PemPublicKeySerializer(new DerPublicKeySerializer()); | |
$PrivateKeyPath = env('KEY_LOCATION').'my.priv'; | |
$PublicKeyPath = storage_path().'/app/'.uniqid().'.pub'; | |
$key = str_replace(" ", "+", Input::get('key')); | |
file_put_contents($PublicKeyPath, "-----BEGIN PUBLIC KEY-----\r\n". $key ."\r\n-----END PUBLIC KEY-----"); | |
$private = $privKeySerializer->parse($loader->loadPrivateKeyData($PrivateKeyPath)); | |
$public = $pubKeySerializer->parse($loader->loadPublicKeyData($PublicKeyPath)); | |
$privateDh = $private->createExchange($this->messages, $public); | |
$key = $privateDh->calculateSharedKey(); | |
return $key; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment