diff options
author | Mario Vavti <mario@mariovavti.com> | 2021-02-04 21:21:22 +0100 |
---|---|---|
committer | Mario Vavti <mario@mariovavti.com> | 2021-02-04 21:21:22 +0100 |
commit | 41f84dabcc14415a47f24ed25a90495bbfcda52a (patch) | |
tree | 21a22b3f7c1c6e92687d33b1978b9ac3971c002e /include/crypto.php | |
parent | cd79d12e5b96fa81b2f54f0e88da6fd6eac8b7e3 (diff) | |
download | volse-hubzilla-41f84dabcc14415a47f24ed25a90495bbfcda52a.tar.gz volse-hubzilla-41f84dabcc14415a47f24ed25a90495bbfcda52a.tar.bz2 volse-hubzilla-41f84dabcc14415a47f24ed25a90495bbfcda52a.zip |
use phpseclib for key transformations
Diffstat (limited to 'include/crypto.php')
-rw-r--r-- | include/crypto.php | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/include/crypto.php b/include/crypto.php index 0d3a5842d..f86d1153c 100644 --- a/include/crypto.php +++ b/include/crypto.php @@ -1,7 +1,7 @@ <?php /** @file */ -use phpseclib3\Crypt\PublicKeyLoader; -use phpseclib3\Math\BigInteger; +use phpseclib\Crypt\RSA; +use phpseclib\Math\BigInteger; require_once('library/ASNValue.class.php'); require_once('library/asn1.php'); @@ -393,12 +393,12 @@ function pkcs1_encode($Modulus,$PublicExponent) { */ function metopem($m, $e) { - $key = PublicKeyLoader::load([ + $rsa = new RSA(); + $rsa->loadKey([ 'e' => new BigInteger($e, 256), 'n' => new BigInteger($m, 256) ]); - hz_syslog('metopem: ' . $key->toString('PKCS8')); - return $key->toString('PKCS8'); + return $rsa->getPublicKey(); /* $der = pkcs8_encode($m,$e); $key = DerToPem($der,false); @@ -423,10 +423,10 @@ function pubrsatome($key,&$m,&$e) { function rsatopem($key) { - $key = PublicKeyLoader::load($key); - hz_syslog('rsatopem: ' . $key->toString('PKCS8')); + $rsa = new RSA(); + $rsa->setPublicKey($key); - return $key->toString('PKCS8'); + return $rsa->getPublicKey(RSA::PUBLIC_FORMAT_PKCS8); /* pubrsatome($key,$m,$e); @@ -434,10 +434,10 @@ function rsatopem($key) { } function pemtorsa($key) { - $key = PublicKeyLoader::load($key); - hz_syslog('pemtorsa: ' . $key->toString('PKCS1')); + $rsa = new RSA(); + $rsa->setPublicKey($key); - return $key->toString('PKCS1'); + return $rsa->getPublicKey(RSA::PUBLIC_FORMAT_PKCS1); /* pemtome($key,$m,$e); return(metorsa($m,$e));*/ @@ -446,9 +446,12 @@ function pemtorsa($key) { function pemtome($key,&$m,&$e) { - $key = PublicKeyLoader::load($key); - $m = new BigInteger($key->n, 256); - $e = new BigInteger($key->e, 256); + $rsa = new RSA(); + $rsa->loadKey($key); + $rsa->setPublicKey(); + + $e = $rsa->modulus->toBytes(); + $m = $rsa->exponent->toBytes(); /* $rsa = new RSA(); @@ -473,13 +476,12 @@ function pemtome($key,&$m,&$e) { function metorsa($m,$e) { - $key = PublicKeyLoader::load([ + $rsa = new RSA(); + $rsa->loadKey([ 'e' => new BigInteger($e, 256), 'n' => new BigInteger($m, 256) ]); - hz_syslog('metorsa: ' . $key->toString('PKCS8')); - - return $key->toString('PKCS8'); + return $rsa->getPublicKey(RSA::PUBLIC_FORMAT_PKCS1); /* $der = pkcs1_encode($m,$e); $key = DerToRsa($der); |