{"action":"created","issue":{"url":"https://api.github.com/repos/phpecc/phpecc/issues/111","labels_url":"https://api.github.com/repos/phpecc/phpecc/issues/111/labels{/name}","comments_url":"https://api.github.com/repos/phpecc/phpecc/issues/111/comments","events_url":"https://api.github.com/repos/phpecc/phpecc/issues/111/events","html_url":"https://github.com/phpecc/phpecc/issues/111","id":119594635,"number":111,"title":"Usage questions","user":{"login":"Minishlink","id":82368,"avatar_url":"https://avatars.githubusercontent.com/u/82368?v=3","gravatar_id":"","url":"https://api.github.com/users/Minishlink","html_url":"https://github.com/Minishlink","followers_url":"https://api.github.com/users/Minishlink/followers","following_url":"https://api.github.com/users/Minishlink/following{/other_user}","gists_url":"https://api.github.com/users/Minishlink/gists{/gist_id}","starred_url":"https://api.github.com/users/Minishlink/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Minishlink/subscriptions","organizations_url":"https://api.github.com/users/Minishlink/orgs","repos_url":"https://api.github.com/users/Minishlink/repos","events_url":"https://api.github.com/users/Minishlink/events{/privacy}","received_events_url":"https://api.github.com/users/Minishlink/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-11-30T22:22:11Z","updated_at":"2015-12-01T22:38:21Z","closed_at":null,"body":"Hi :)\r\n\r\nFirst of all, thanks for your work on this library.\r\n\r\nI would like to implement [this particular use case](https://tools.ietf.org/html/draft-thomson-webpush-encryption-00#section-3) (Web Push API) for my library [WebPush](https://github.com/Minishlink/web-push).\r\n\r\nI'm new to cryptography. I'm not sure if you've written this library for people with a minimum of experience with cryptography or not, but I tried to do it anyway.\r\n\r\nSo far, I have written this:\r\n```php\r\n$localCurveGenerator = EccFactory::getNistCurves()->generator256();\r\n$localPrivateKey = $localCurveGenerator->createPrivateKey();\r\n$localPublicKey = $localPrivateKey->getPublicKey();\r\n\r\n$messages = new MessageFactory(EccFactory::getAdapter());\r\n$message = $messages->plaintext($payload, 'sha256');\r\n\r\n$pubKeySerializer = new PemPublicKeySerializer(new DerPublicKeySerializer());\r\n$remotePublicKey = $pubKeySerializer->parse($userPublicKey);\r\n\r\n$dh = $localPrivateKey->createExchange($messages, $remotePublicKey);\r\n$salt = hash('sha256', $dh->calculateSharedKey(), true);\r\n\r\n$cipherText = $dh->encrypt($message);\r\n\r\nreturn array(\r\n    'localPublicKey' => base64_encode($localPublicKey->getContent()), // this doesn't exist\r\n    'salt' => base64_encode($salt),\r\n    'cipherText' => base64_encode($cipherText->getContent()),\r\n);\r\n```\r\n\r\nI have several questions:\r\n1. I get `$salt` the way above because I naively thought it was the same as the `$key` in your `EcDH->encrypt()`. Am I right or not at all?\r\n2. How do you get content of a `PublicKey` ? Am I right to assume I can do it by calling `getPoint()->getX()` on it? Or does this return something else?\r\n3. In the code above `$userPublicKey` is in fact a base 64 encoded string of the user public key. One example is: `BKD9anmcirmuG9J4wlPAmezLpqvrBd3mD2Q680XfJNkCzjIx2AwTcUcSrBSzJI9eCkk61ZGbjAglCoPQO9kh0g4=`. The parser throws a \"Invalid data.\". Do you know why ?"},"comment":{"url":"https://api.github.com/repos/phpecc/phpecc/issues/comments/161119407","html_url":"https://github.com/phpecc/phpecc/issues/111#issuecomment-161119407","issue_url":"https://api.github.com/repos/phpecc/phpecc/issues/111","id":161119407,"user":{"login":"Minishlink","id":82368,"avatar_url":"https://avatars.githubusercontent.com/u/82368?v=3","gravatar_id":"","url":"https://api.github.com/users/Minishlink","html_url":"https://github.com/Minishlink","followers_url":"https://api.github.com/users/Minishlink/followers","following_url":"https://api.github.com/users/Minishlink/following{/other_user}","gists_url":"https://api.github.com/users/Minishlink/gists{/gist_id}","starred_url":"https://api.github.com/users/Minishlink/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Minishlink/subscriptions","organizations_url":"https://api.github.com/users/Minishlink/orgs","repos_url":"https://api.github.com/users/Minishlink/repos","events_url":"https://api.github.com/users/Minishlink/events{/privacy}","received_events_url":"https://api.github.com/users/Minishlink/received_events","type":"User","site_admin":false},"created_at":"2015-12-01T22:38:21Z","updated_at":"2015-12-01T22:38:21Z","body":"Thanks for your explanation, it was very helpful.\r\n\r\nSo I followed your advice and didn't use the encryption feature of the EcDH class. First I thought of using mcrypt (just like phpecc), but I saw that it was a deprecated library since 2007 and that it was recommended to use openssl now, so I used openssl.\r\n\r\nFor 2., I meant the binary representation. I used the UncompressedPointSerializer to get it. :)\r\n\r\nSo I've now written [this code](https://github.com/Minishlink/web-push/blob/8d55f0ae6406547fd0a3247e1979982eb77e099a/src/WebPush.php#L141).\r\n\r\nI have one last question related to phpecc. In phpecc, computing the shared secret sums up to the following line in my code:\r\n```php\r\n/** @var $userPublicKeyObject PublicKey */\r\n/** @var $localPrivateKeyObject PrivateKey */\r\n$sharedSecret = $userPublicKeyObject->getPoint()->mul($localPrivateKeyObject->getSecret())->getX();\r\n```\r\nHere, why do we get only the X value ? And not the X and Y value with a prefix just like the public keys ?\r\n"}}