Signatures

The following PHP signature examples use the phpseclib secure communications library.

Sign data

Signing data using RSA private key with PKCS1 v1.5 padding and SHA256 hash:

<?
public function rsa_decrypt($key, $package) {
    $rsa = new Crypt_RSA();
    $rsa->setHash("sha256");
    $rsa->setSignatureMode(CRYPT_RSA_SIGNATURE_PKCS1);
    $rsa->loadKey($key);
    $signature = base64_encode($rsa->sign(base64_decode($package)));
    return $signature;
}
?>

Verify signature

Decrypt a package using RSA private key with PKCS1-OAEP padding:

<?
public function rsa_verify_sign($key, $signature, $package) {
    $rsa = new Crypt_RSA();
    $rsa->setHash("sha256");
    $rsa->setSignatureMode(CRYPT_RSA_SIGNATURE_PKCS1);
    $rsa->loadKey($key);
    $verify = $rsa->verify(base64_decode($package), $signature);
    return $verify;
}
?>

User Contributed

LaunchKey links to user contributed code as a resource to its community. LaunchKey does not in any way guarantee or warrant the quality and security of these code bases. User contributed code is supported by the creators. If you do find a link from the site to user contributed code that is malicious or inappropriate in any way, please report that link to LaunchKey immediately and we will investigate the claim. Submit any issue to LaunchKey support at https://launchkey.com./support. ×