public static function meToPem($m, $e)
{
$rsa = new RSA();
- $rsa->loadKey([
- 'e' => new BigInteger($e, 256),
- 'n' => new BigInteger($m, 256)
- ]);
+ $rsa->loadKey(
+ [
+ 'e' => new BigInteger($e, 256),
+ 'n' => new BigInteger($m, 256)
+ ]);
return $rsa->getPublicKey();
}
*/
public static function rsaToPem(string $key)
{
- $publicKey = new RSA();
- $publicKey->setPublicKey($key);
+ $rsa = new RSA();
+ $rsa->setPublicKey($key);
- return $publicKey->getPublicKey(RSA::PUBLIC_FORMAT_PKCS8);
+ return $rsa->getPublicKey(RSA::PUBLIC_FORMAT_PKCS8);
}
/**
*/
public static function pemToMe(string $key, &$modulus, &$exponent)
{
- $publicKey = new RSA();
- $publicKey->loadKey($key);
- $publicKey->setPublicKey();
+ $rsa = new RSA();
+ $rsa->loadKey($key);
+ $rsa->setPublicKey();
- $modulus = $publicKey->modulus->toBytes();
- $exponent = $publicKey->exponent->toBytes();
+ $modulus = $rsa->modulus->toBytes();
+ $exponent = $rsa->exponent->toBytes();
}
/**
/**
* Encrypt a string with 'aes-256-cbc' cipher method.
- *
+ *
* Ported from Hubzilla: https://framagit.org/hubzilla/core/blob/master/include/crypto.php
- *
+ *
* @param string $data
* @param string $key The key used for encryption.
* @param string $iv A non-NULL Initialization Vector.
- *
+ *
* @return string|boolean Encrypted string or false on failure.
*/
private static function encryptAES256CBC($data, $key, $iv)
/**
* Decrypt a string with 'aes-256-cbc' cipher method.
- *
+ *
* Ported from Hubzilla: https://framagit.org/hubzilla/core/blob/master/include/crypto.php
- *
+ *
* @param string $data
* @param string $key The key used for decryption.
* @param string $iv A non-NULL Initialization Vector.
- *
+ *
* @return string|boolean Decrypted string or false on failure.
*/
private static function decryptAES256CBC($data, $key, $iv)
Crypto::pemToMe($key, $m, $e);
$expectedRSA = new RSA();
- $expectedRSA->loadKey([
- 'e' => new BigInteger($e, 256),
- 'n' => new BigInteger($m, 256)
- ]);
+ $expectedRSA->loadKey(
+ [
+ 'e' => new BigInteger($e, 256),
+ 'n' => new BigInteger($m, 256)
+ ]);
$this->assertEquals($expectedRSA->getPublicKey(), $key);
}