Encrypt filtered key for use with the Connect API
@param array $definition The filtered key definition
@param string $masterKey The master key for the Connect project
@return String
553917
public static function generateFilteredKey($definition, $masterKey) {
        $cipher = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
        $ivSize = mcrypt_enc_get_iv_size($cipher);
        $iv = mcrypt_create_iv($ivSize, MCRYPT_RAND);
        
        $definitionWithPading = self::_pad(json_encode($definition),16);
    
        if (mcrypt_generic_init($cipher, $masterKey, $iv) != -1) {
            $cipherText = mcrypt_generic($cipher,$definitionWithPading);
            mcrypt_generic_deinit($cipher);
            $encrypted = sprintf("%s-%s",bin2hex($iv),bin2hex($cipherText)); 
            
            return $encrypted;
        }
    }
1360186
public function getPrivateKeyPassphrase()
    {
        if (isset($this->raw->{'key-pass'})
            && is_string($this->raw->{'key-pass'})) {
            return $this->raw->{'key-pass'};
        }

        return null;
    }
132712
public function encrypt($str = null, $key = null)
    {
        if (!is_null($key)) {
            $this->setSalt($key);
        }
        srand((double)microtime()*1000000);
        $key_encrypt    = md5(rand(0,32000));
        $count          = 0;
        $tmp            = '';
        for ($ctr=0;$ctr<strlen($str);$ctr++) {
            if ($count==strlen($key_encrypt)) {
                $count=0;
            }
            $tmp.= substr($key_encrypt,$count,1).(substr($str,$ctr,1) ^ substr($key_encrypt,$count,1) );
            $count++;
        }
        return base64_encode(self::getEncryptionKey($tmp));
    }
1252195
public function getPrivateMasterKey()
    {
        if (!$this->privateMasterKey) {
            $masterKey = $this->getMasterKey();
            openssl_pkey_export($masterKey, $this->privateMasterKey);
        }
        return $this->privateMasterKey;
    }
1304820
public function getDerivedKey($type)
    {
        if ($this->_masterKey === null) {
            throw new CryptException(['getDerivedKey for `:type` type Failed: master key is not set', 'type' => $type]);
        }

        return md5($this->_masterKey . ':' . $type);
    }
1345000
protected function createValueSchema(array $definition)
    {
        if (!isset($definition['properties'])) {
            throw new Exception("Missing required key 'properties' within assoc definition.");
        }
        return $this->getSchema()->getFactory()->createSchema(
            $this->getName().'_type',
            [ 'type' => 'assoc', 'properties' => $definition['properties'] ],
            $this
        );
    }
787853
def encrypt(key_id, plaintext, encryption_context=None, grant_tokens=None,
            region=None, key=None, keyid=None, profile=None):
    '''
    
    '''
    conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile)

    r = {}
    try:
        ciphertext = conn.encrypt(
            key_id,
            plaintext,
            encryption_context=encryption_context,
            grant_tokens=grant_tokens
        )
        r['ciphertext'] = ciphertext['CiphertextBlob']
    except boto.exception.BotoServerError as e:
        r['error'] = __utils__['boto.get_error'](e)
    return r
308301
public function getPublicMasterKey()
    {
        if (!$this->publicMasterKey) {
            $masterKey = $this->getMasterKey();
            $publicKeyDetails = openssl_pkey_get_details($masterKey);
            $this->publicMasterKey = $publicKeyDetails['key'];
        }
        return $this->publicMasterKey;
    }
1124069
public function build($definition, $context = null, $name = null)
    {
        if ($definition instanceof ProviderInterface) {
            return $this->getProviderValue($definition, $context);
        } elseif ($definition instanceof FieldInterface) {
            return $definition->getResult($context);
        } elseif (is_array($definition)) {
            $result = [];
            foreach ($definition as $key => $value) {
                $result[$key] = $this->build($value, $context);
            }

            return new Record(
                $name === null ? 'record' : $name, 
                $result
            );
        } elseif (is_string($definition)) {
            if ($context !== null) {
                if (is_array($context)) {
                    if (array_key_exists($definition, $context)) {
                        return $context[$definition];
                    } else {
                        throw new RuntimeException('Referenced unknown key "' . $definition . '" in context');
                    }
                } elseif ($context instanceof \ArrayAccess) {
                    if ($context->offsetExists($definition)) {
                        return $context->offsetGet($definition);
                    } else {
                        throw new RuntimeException('Referenced unknown key "' . $definition . '" in context');
                    }
                } else {
                    throw new RuntimeException('Context must be either an array or instance of ArrayAccess');
                }
            } else {
                return $definition;
            }
        } else {
            return $definition;
        }
    }
873697
public function getPrivateKey()
    {
        if (!$this->xml) {
            return false;
        }
        $RSASK = $this->xml->getElementsByTagName('RSASK')->item(0);
        return $RSASK ? $RSASK->nodeValue : false;
    }
1280241
private function setPrefixKey()
    {
        if (null !== $this->getContext()) {
            $this->_prefix_key = md5($this->getContext());
        }

        return $this;
    }
1093803
public function createDictionary(DictionaryDefinition $definition): DictionaryInterface
    {
        $builder = $this->getDictionaryBuilder($definition);

        /** @var DictionaryBuilderInterface $builder */
        return $builder->build($this, $definition);
    }
38773
private function filterOutAbstractDefinitions(array $definitions): array
    {
        foreach ($definitions as $key => $definition) {
            if ($definition->isAbstract()) {
                unset($definitions[$key]);
            }
        }

        return $definitions;
    }
955873
public static function decrypt($encryptedText, $key, $cipher)
    {
        $cipher = strtolower($cipher);

        if (false === in_array($cipher, openssl_get_cipher_methods())) {
            throw new \LogicException(sprintf('Cipher %s not supported', $cipher));
        }

        $encryptedText = base64_decode($encryptedText);

        $ivLen = openssl_cipher_iv_length($cipher);
        $iv = substr($encryptedText, 0, $ivLen);

        $hmac = substr($encryptedText, $ivLen, 32);
        $cipherTextRaw = substr($encryptedText, $ivLen + 32);

        $plainText = openssl_decrypt($cipherTextRaw, $cipher, $key, OPENSSL_RAW_DATA, $iv);
        $calculatedHmac = hash_hmac('sha256', $cipherTextRaw, $key, true);

        if (false === hash_equals($hmac, $calculatedHmac)) {
            throw new \LogicException('Decrypt failed.');
        }

        return $plainText;
    }
132764
public function createWritableDictionary(DictionaryDefinition $definition): WritableDictionaryInterface
    {
        $builder = $this->getDictionaryBuilder($definition);

        /** @var DictionaryBuilderInterface $builder */
        return $builder->buildWritable($this, $definition);
    }
1253637
public function toDTO($filterByKey = null)
    {
        $toDTO = ["address" => $this->toClean()];

        // KeyPair's public key/private key not always set
        // because \NEM\Models\Address is used for simple Address formatting
        if (!empty($this->publicKey))
            $toDTO["publicKey"] = $this->publicKey;

        if (!empty($this->privateKey))
            $toDTO["privateKey"] = $this->privateKey;

        if ($filterByKey && isset($toDTO[$filterByKey]))
            return $toDTO[$filterByKey];

        return $toDTO;
    }
1206578
public function store(PrivateKey $privateKey, $name, array $meta = null)
    {
        $exportedData = $this->privateKeyExporter->exportPrivateKey($privateKey);

        $this->keyStorage->store(new KeyEntry($name, $exportedData, $meta));
    }