Inheritance: extends ParagonIE\Halite\Key
 /**
  * @param string $keyMaterial - The actual key data
  * @param bool $signing - Is this a signing key?
  */
 public function __construct(string $keyMaterial = '', ...$args)
 {
     if (CryptoUtil::safeStrlen($keyMaterial) !== \Sodium\CRYPTO_SIGN_SECRETKEYBYTES) {
         throw new InvalidKey('Signature secret key must be CRYPTO_SIGN_SECRETKEYBYTES bytes long');
     }
     parent::__construct($keyMaterial, true);
 }
Example #2
0
 /**
  * @param HiddenString $keyMaterial - The actual key data
  * @throws InvalidKey
  */
 public function __construct(HiddenString $keyMaterial)
 {
     if (CryptoUtil::safeStrlen($keyMaterial->getString()) !== \Sodium\CRYPTO_BOX_SECRETKEYBYTES) {
         throw new InvalidKey('Encryption secret key must be CRYPTO_BOX_SECRETKEYBYTES bytes long');
     }
     parent::__construct($keyMaterial);
 }
Example #3
0
 /**
  * @param HiddenString $keyMaterial - The actual key data
  * @throws InvalidKey
  */
 public function __construct(HiddenString $keyMaterial)
 {
     if (CryptoUtil::safeStrlen($keyMaterial->getString()) !== \Sodium\CRYPTO_SIGN_SECRETKEYBYTES) {
         throw new InvalidKey('Signature secret key must be CRYPTO_SIGN_SECRETKEYBYTES bytes long');
     }
     parent::__construct($keyMaterial);
     $this->isSigningKey = true;
 }
Example #4
0
 public function testDeriveSigningKey()
 {
     list($sign_secret, $sign_public) = ASecretKey::deriveFromPassword('apple', "\t\n\v\f\r" . "", Key::CRYPTO_SIGN);
     $this->assertTrue($sign_secret instanceof ASecretKey);
     $this->assertTrue($sign_public instanceof APublicKey);
     // Can this be used?
     $message = 'This is a test message';
     $signed = Asymmetric::sign($message, $sign_secret);
     $this->assertTrue(Asymmetric::verify($message, $sign_public, $signed));
     $this->assertEquals($sign_public->get(), "þ\t†E·õÂbÈagÖ\t" . "•§”\\æÕU–ãuˆ4");
 }