loadEncryptionKeyPair() public static method

Load an asymmetric encryption key pair from a file
public static loadEncryptionKeyPair ( string $filePath ) : EncryptionKeyPair
$filePath string
return EncryptionKeyPair
Beispiel #1
0
 public function testFileStorage()
 {
     $filename = \tempnam(__DIR__ . '/tmp/', 'key');
     $key = KeyFactory::generateEncryptionKeyPair();
     KeyFactory::save($key, $filename);
     $copy = KeyFactory::loadEncryptionKeyPair($filename);
     $this->assertEquals($key->getPublicKey()->getRawKeyMaterial(), $copy->getPublicKey()->getRawKeyMaterial());
     \unlink($filename);
 }
Beispiel #2
0
             $keys[$index] = KeyFactory::loadEncryptionKey($path);
             break;
         case 'EncryptionPublicKey':
             $keys[$index] = KeyFactory::loadEncryptionPublicKey($path);
             break;
         case 'EncryptionSecretKey':
             $keys[$index] = KeyFactory::loadEncryptionSecretKey($path);
             break;
         case 'SignaturePublicKey':
             $keys[$index] = KeyFactory::loadSignaturePublicKey($path);
             break;
         case 'SignatureSecretKey':
             $keys[$index] = KeyFactory::loadSignatureSecretKey($path);
             break;
         case 'EncryptionKeyPair':
             $keys[$index] = KeyFactory::loadEncryptionKeyPair($path);
             break;
         case 'SignatureKeyPair':
             $keys[$index] = KeyFactory::loadSignatureKeyPair($path);
             break;
         default:
             throw new \Error(\trk('errors.crypto.unknown_key_type', $keyConfig['type']));
     }
 } else {
     // We must generate this key/keypair at once:
     switch ($keyConfig['type']) {
         case 'EncryptionPublicKey':
         case 'SignaturePublicKey':
             throw new \Error(\trk('errors.crypto.cannot_generate_public_key'));
         case 'AuthenticationKey':
             $keys[$index] = KeyFactory::generateAuthenticationKey();