diff options
author | Mario <mario@mariovavti.com> | 2024-01-03 19:20:28 +0000 |
---|---|---|
committer | Mario <mario@mariovavti.com> | 2024-01-03 19:20:28 +0000 |
commit | 852678e238eaa28199640b4b2a856e53d707ca24 (patch) | |
tree | 062002ea1841d7c96383a66c0e9d3caaf6596eb3 /Zotlabs/Lib/Multibase.php | |
parent | 16e6eec3fb2bfb5a34c9dc94d46232be8461a947 (diff) | |
download | volse-hubzilla-852678e238eaa28199640b4b2a856e53d707ca24.tar.gz volse-hubzilla-852678e238eaa28199640b4b2a856e53d707ca24.tar.bz2 volse-hubzilla-852678e238eaa28199640b4b2a856e53d707ca24.zip |
port multibase and jcsedssa2022 libs from streams
Diffstat (limited to 'Zotlabs/Lib/Multibase.php')
-rw-r--r-- | Zotlabs/Lib/Multibase.php | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/Zotlabs/Lib/Multibase.php b/Zotlabs/Lib/Multibase.php new file mode 100644 index 000000000..099723630 --- /dev/null +++ b/Zotlabs/Lib/Multibase.php @@ -0,0 +1,34 @@ +<?php +namespace Zotlabs\Lib; + +use StephenHill\Base58; + +class Multibase { + + protected $key = null; + + public function __construct() { + return $this; + } + + public function publicKey($key) { + $base58 = new Base58(); + $raw = hex2bin('ed01') . sodium_base642bin($key, SODIUM_BASE64_VARIANT_ORIGINAL_NO_PADDING); + return 'z' . $base58->encode($raw); + } + + public function secretKey($key) { + $base58 = new Base58(); + $raw = hex2bin('8026') . sodium_base642bin($key, SODIUM_BASE64_VARIANT_ORIGINAL_NO_PADDING); + return 'z' . $base58->encode($raw); + } + + public function decode($key, $binary = false) { + $base58 = new Base58(); + $key = substr($key,1); + $raw = $base58->decode($key); + $binaryKey = substr($raw, 2); + return $binary ? $binaryKey : sodium_bin2base64($binaryKey, SODIUM_BASE64_VARIANT_ORIGINAL_NO_PADDING); + } + +} |