Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
$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
You can’t perform that action at this time.