diff options
author | zotlabs <mike@macgirvin.com> | 2017-10-08 12:42:54 -0700 |
---|---|---|
committer | zotlabs <mike@macgirvin.com> | 2017-10-08 12:42:54 -0700 |
commit | 5cc6c6c1e97743b208b90f2a05b23196df787f36 (patch) | |
tree | 77b85421af0e0052f5b0ab23fc95abd51bc89728 /Zotlabs/Lib/JSalmon.php | |
parent | d2e22d8c2f5ee7c0bca1fa63d39a6822582106e8 (diff) | |
parent | 991db280be4c3cbbff4fb1e4dae8f303a487ed3f (diff) | |
download | volse-hubzilla-5cc6c6c1e97743b208b90f2a05b23196df787f36.tar.gz volse-hubzilla-5cc6c6c1e97743b208b90f2a05b23196df787f36.tar.bz2 volse-hubzilla-5cc6c6c1e97743b208b90f2a05b23196df787f36.zip |
Merge branch 'dev' of https://github.com/redmatrix/hubzilla into dev_merge
Diffstat (limited to 'Zotlabs/Lib/JSalmon.php')
-rw-r--r-- | Zotlabs/Lib/JSalmon.php | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/Zotlabs/Lib/JSalmon.php b/Zotlabs/Lib/JSalmon.php new file mode 100644 index 000000000..43d5f9d09 --- /dev/null +++ b/Zotlabs/Lib/JSalmon.php @@ -0,0 +1,38 @@ +<?php + +namespace Zotlabs\Lib; + + +class JSalmon { + + static function sign($data,$key_id,$key) { + + $arr = $data; + $data = json_encode($data,JSON_UNESCAPED_SLASHES); + $data = base64url_encode($data, false); // do not strip padding + $data_type = 'application/x-zot+json'; + $encoding = 'base64url'; + $algorithm = 'RSA-SHA256'; + + $data = preg_replace('/\s+/','',$data); + + // precomputed base64url encoding of data_type, encoding, algorithm concatenated with periods + + $precomputed = '.' . base64url_encode($data_type,false) . '.YmFzZTY0dXJs.UlNBLVNIQTI1Ng=='; + + $signature = base64url_encode(rsa_sign($data . $precomputed, $key), false); + + return ([ + 'signed' => true, + 'data' => $data, + 'data_type' => $data_type, + 'encoding' => $encoding, + 'alg' => $algorithm, + 'sigs' => [ + 'value' => $signature, + 'key_id' => base64url_encode($key_id) + ] + ]); + + } +}
\ No newline at end of file |