protected function afterGenerateKeyPair(KeyPairInterface $keyPair)
    {
        if ($keyPair instanceof SecureKeyPairInterface) {
            $masterKeyPairProvider = $this->getMasterKeyPairProvider();
            $masterKeyName = $this->getMasterKeyName();
            if ($masterKeyPairProvider === null) {
                throw new InaccessibleKeyPairException('Provider has an invalid master key provider specified for its secure keys');
            }
            if (!$masterKeyPairProvider->has($masterKeyName)) {
                $masterKey = $masterKeyPairProvider->generate($masterKeyName);
            } else {
                $masterKey = $masterKeyPairProvider->get($masterKeyName);
            }
            $keyPair->lock($masterKey);
        }
        return $keyPair;
    }