ParagonIE\Halite\File::sign PHP Method

sign() public static method

Specifically: 1. Calculate the BLAKE2b-512 checksum of the file, with the signer's Ed25519 public key used as a BLAKE2b key. 2. Sign the checksum with Ed25519, using the corresponding public key.
public static sign ( string | resource $filename, SignatureSecretKey $secretKey, boolean $raw_binary = false ) : string
$filename string | resource File name or file handle
$secretKey SignatureSecretKey Secret key for digital signatures
$raw_binary boolean Default: return hexadecimal
return string Detached signature for the file
    public static function sign($filename, SignatureSecretKey $secretKey, bool $raw_binary = false) : string
    {
        if (\is_resource($filename) || \is_string($filename)) {
            $readOnly = new ReadOnlyFile($filename);
            $signature = self::signData($readOnly, $secretKey, $raw_binary);
            $readOnly->close();
            return $signature;
        }
        throw new InvalidType('Argument 1: Expected a filename or resource');
    }

Same methods

File::sign ( string | resource $filename, SignatureSecretKey $secretKey, mixed $encoding = Halite::ENCODE_BASE64URLSAFE ) : string

Usage Example

Example #1
0
 public function testSign()
 {
     $keypair = KeyFactory::generateSignatureKeyPair();
     $secretkey = $keypair->getSecretKey();
     $publickey = $keypair->getPublicKey();
     $signature = File::sign(__DIR__ . '/tmp/paragon_avatar.png', $secretkey);
     $this->assertTrue(!empty($signature));
     $this->assertTrue(File::verify(__DIR__ . '/tmp/paragon_avatar.png', $publickey, $signature));
 }