这是indexloc提供的服务,不要输入任何密码
Skip to content
This repository was archived by the owner on Sep 1, 2025. It is now read-only.
/ php_jwsign Public archive

This is a function wrapping through the Openssl to sign and validate the data, which ensures the integrity and security of the original data.

License

Notifications You must be signed in to change notification settings

yakeing/php_jwsign

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

86 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Json Wed Sign (RSA)

This is a function wrapping through the Openssl to sign and validate the data, which ensures the integrity and security of the original data.

Travis CI

Travis-ci

Packagist

Version Downloads

Github

Downloads Size tag Language Php

Installation

Use Composer to install the library.


    $ composer require yakeing/php_jwsign

JWSign init

    $jwsign = new jwsign();
    $jwsign->SetPrivate($accesskey);

Get Pubkey

    $Pubkey = $jwsign->GetPubkey();

    var_dump($Pubkey);
    array(3) {
        ["pub"]=>string(451) "-----BEGIN PUBLIC KEY-----\nMIIBIjA....NjQIDAQA\n-----END PUBLIC KEY----"
        ["bits"]=>int(2048)
        ["kid"]=>string(43) "cjbdM-CeRfP...5BNYQuksIIgmk"
    }

Sign Message

    $Message = base64_encode('
        {
            "method":"pay",
            "charset":"utf-8",
            "version":"1.0",
            "token":"NAM...YgV"
        }
    ');

    $JsonStr = $jwsign->SignMessage($Message);

    var_dump($JsonStr);
    string(557) "{
        "message":"eyJtZXRiO...Z1YifQ==",
        "nonce":"MmlhaDE1MD...MTgwLjEwNDc1OTAw",
        "kid":"cjOdM-CORfPGa...j-0I5BNYQuksIIgmk",
        "sign":"hXvBULK2wSroVFZ...-HYHG7l8Epixikg"
        }"

Pubkey Verify

    $value = '{
        "message":"eyJtZXRiO...Z1YifQ==",
        "nonce":"MmlhaDE1MD...MTgwLjEwNDc1OTAw",
        "kid":"cjOdM-CORfPGa...j-0I5BNYQuksIIgmk"
        }';
    $sign = 'hXvBULK2wvSroVFZ...-HKbHGDYHG7l8Epixikg';
    $pub = '-----BEGIN PUBLIC KEY-----\nMIIBIjA....NjQIDAQA\n-----END PUBLIC KEY----';

    $Str = $jwsign->PubkeyVerify($value, $sign, $pub);

    var_dump($Str);
    bool(true)

Get Message

    $value = '{
        "message":"eyJtZXRiO...Z1YifQ==",
        "nonce":"MmlhaDE1MD...MTgwLjEwNDc1OTAw",
        "kid":"cjOdM-CORfPGa...j-0I5BNYQuksIIgmk"
        }';
    $Str = json_decode($value, true);

    var_dump(base64_decode($Str['message']));
    string(100) "{
            "method":"pay",
            "charset":"utf-8",
            "version":"1.0",
            "token":"NAM...YgV"
        }"

Donate

Your donation makes CODE better.

Bitcoin

1FYbZECgs3V3zRx6P7yAu2nCDXP2DHpwt8

Bitcoin

WeChat

WeChat

Alipay

Alipay

Author

weibo: yakeing

twitter: yakeing

About

This is a function wrapping through the Openssl to sign and validate the data, which ensures the integrity and security of the original data.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages