paragonie / paseto

Platform-Agnostic Security Tokens
https://paseto.io
Other
3.25k stars 108 forks source link

Secret keys must be 32 or 64 bytes long; 96 given. #32

Closed pascaldevink closed 6 years ago

pascaldevink commented 6 years ago

Following along with the usage documentation here: https://github.com/paragonie/past/tree/master/docs/02-PHP-Library, I've ran into the following exception when executing the first block of code:

PHP Fatal error:  Uncaught Exception: Secret keys must be 32 or 64 bytes long; 96 given. in vendor/paragonie/past/src/Keys/AsymmetricSecretKey.php:40
Stack trace:
#0 encrypt.php(11): ParagonIE\PAST\Keys\AsymmetricSecretKey->__construct('\x84\x9E\xAC\xFB6t^\xBD\xEC\xC3Hq\xFA\xAD\x06...', 'v2')
#1 {main}
  thrown in vendor/paragonie/past/src/Keys/AsymmetricSecretKey.php on line 40

This is the code I'm using:

<?php

require('vendor/autoload.php');

use ParagonIE\PAST\Keys\{
    AsymmetricSecretKey,
    SymmetricKey
};

$privateKey = new AsymmetricSecretKey(sodium_crypto_sign_keypair());
$publicKey = $privateKey->getPublicKey();

$sharedKey = new SymmetricKey(random_bytes(32));

I'm running this on macOS with PHP 7.1. I ran it with both libsodium and gmp installed and uninstalled, but got the same exception.

Did anything change in the implementation and is the documentation not up-to-date, or is there something else going on?

paragonie-scott commented 6 years ago

D'oh. I made a documentation error.

- $privateKey = new AsymmetricSecretKey(sodium_crypto_sign_keypair());
- $publicKey = $privateKey->getPublicKey();
+ $keypair = sodium_crypto_sign_keypair();
+ $privateKey = new AsymmetricSecretKey(sodium_crypto_sign_secretkey($keypair));
+ $publicKey = new AsymmetricPublicKey(sodium_crypto_sign_publickey($keypair));

In hindsight, I should probably make this function tolerate entire keypairs though.

pascaldevink commented 6 years ago

Thanks for that! That works 💯

paragonie-scott commented 6 years ago

https://github.com/paragonie/past/commit/ed20dd31506eb956e7c058218b5e6ca78692d706 allows 96-byte keys.