Get the configuration for encrypt operations

@param int $major
@param int $minor
@return array
@throws InvalidMessage
180527
protected static function getConfigChecksum(int $major, int $minor): array
    {
        if ($major === 3 || $major === 4) {
            switch ($minor) {
                case 0:
                    return [
                        'CHECKSUM_PUBKEY' => true,
                        'BUFFER' => 1048576,
                        'HASH_LEN' => \SODIUM_CRYPTO_GENERICHASH_BYTES_MAX
                    ];
            }
        }
        // @codeCoverageIgnoreStart
        throw new InvalidMessage(
            'Invalid version tag'
        );
        // @codeCoverageIgnoreEnd
    }
288072
function encrypt($plaintext)
    {
        if ($this->engine != Base::ENGINE_INTERNAL) {
            return parent::encrypt($plaintext);
        }
        return $this->_crypt($plaintext, self::ENCRYPT);
    }
209315
protected function _getJsonPayload($payload)
    {
        $payload = json_decode(base64_decode($payload), true);

        if (! $this->_validPayload($payload)) {
            throw new AnEncrypterException('The payload is invalid.');
        }

        if (! $this->_validMac($payload)) {
            throw new AnEncrypterException('The MAC is invalid.');
        }

        return $payload;
    }
8487
static public function decryptJson($ciphertextFileName, Config $config = null) {
        $content = self::decrypt($ciphertextFileName, $config);
        $data = json_decode($content, JSON_OBJECT_AS_ARRAY);
        Util::isArrayOrFail("Encrypted secrets", $data);
        return $data;
    }
692320
public static function EncryptMessage ($message, $key, $options = []) {
		$options['module'] = \MCRYPT_MODE_ECB;
		return static::Encrypt($message, $key, $options);
	}
951656
public static function getSecurityLevels(
        string $level = self::INTERACTIVE,
        int $alg = SODIUM_CRYPTO_PWHASH_ALG_ARGON2ID13
    ): array {
        switch ($level) {
            case self::INTERACTIVE:
                if ($alg === SODIUM_CRYPTO_PWHASH_ALG_ARGON2I13) {
                    // legacy opslimit and memlimit
                    return [4, 33554432];
                }
                return [
                    \SODIUM_CRYPTO_PWHASH_OPSLIMIT_INTERACTIVE,
                    \SODIUM_CRYPTO_PWHASH_MEMLIMIT_INTERACTIVE
                ];
            case self::MODERATE:
                if ($alg === SODIUM_CRYPTO_PWHASH_ALG_ARGON2I13) {
                    // legacy opslimit and memlimit
                    return [6, 134217728];
                }
                return [
                    \SODIUM_CRYPTO_PWHASH_OPSLIMIT_MODERATE,
                    \SODIUM_CRYPTO_PWHASH_MEMLIMIT_MODERATE
                ];
            case self::SENSITIVE:
                if ($alg === SODIUM_CRYPTO_PWHASH_ALG_ARGON2I13) {
                    // legacy opslimit and memlimit
                    return [8, 536870912];
                }
                return [
                    \SODIUM_CRYPTO_PWHASH_OPSLIMIT_SENSITIVE,
                    \SODIUM_CRYPTO_PWHASH_MEMLIMIT_SENSITIVE
                ];
            default:
                throw new InvalidType(
                    'Invalid security level for Argon2i'
                );
        }
    }
501657
protected static function rsaEncrypt($plaintext, PublicKey $rsaPublicKey)
    {
        $rsa = self::getRsa(RSA::ENCRYPTION_OAEP);

        $return = $rsa->loadKey($rsaPublicKey->getKey());
        if ($return === false) {
            throw new InvalidKeyException('Ecryption failed due to invalid key');
        }

        return $rsa->encrypt($plaintext);
    }
1090226
function encrypt($text, $keys, $sign_key = null)
    {
        try {
            foreach ($keys as $key) {
                $this->gpg->addEncryptKey($key->reference);
            }

            if ($sign_key) {
                $this->gpg->addSignKey($sign_key->reference, $sign_key->password);

                $res     = $this->gpg->encryptAndSign($text, true);
                $sigInfo = $this->gpg->getLastSignatureInfo();

                $this->last_sig_algorithm = $sigInfo->getHashAlgorithmName();

                return $res;
            }

            return $this->gpg->encrypt($text, true);
        }
        catch (Exception $e) {
            return $this->get_error_from_exception($e);
        }
    }
1217621
def get_major_minor(ilo_ver_str):
    
    if not ilo_ver_str:
        return None
    try:
        # Note(vmud213):This logic works for all strings
        # that contain the version info as <major>.<minor>
        # Formats of the strings:
        #    Release version ->  "2.50 Feb 18  2016"
        #    Debug version   ->  "iLO 4 v2.50"
        #    random version  ->  "XYZ ABC 2.30"
        pattern = re.search(ILO_VER_STR_PATTERN, ilo_ver_str)
        if pattern:
            matched = pattern.group(0)
            if matched:
                return matched
            return None
    except Exception:
        return None
706021
public function encrypt($encrypt, $key)
    {
        $inputParams = [
            'encrypt' => $encrypt,
            'key'     => $key,
        ];
        $this->debug->info(__FUNCTION__, 'Input Params: ' . json_encode($inputParams));
        $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_ECB), MCRYPT_RAND);
        $this->debug->debug(__FUNCTION__, 'IV Key: ' . json_encode($iv));
        $encrypted = base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, pack("H*", $key), $encrypt, MCRYPT_MODE_ECB, $iv));
        $this->debug->info(__FUNCTION__, 'encrypt Result: ' . json_encode($encrypted));

        return $encrypted;
    }
1373644
public static function unpackMessageForDecryption(string $ciphertext): array
    {
        $length = Binary::safeStrlen($ciphertext);

        // Fail fast on invalid messages
        if ($length < Halite::VERSION_TAG_LEN) {
            throw new InvalidMessage(
                'Message is too short'
            );
        }

        // The first 4 bytes are reserved for the version size
        $version = Binary::safeSubstr(
            $ciphertext,
            0,
            Halite::VERSION_TAG_LEN
        );
        $config = SymmetricConfig::getConfig($version, 'encrypt');

        if ($length < $config->SHORTEST_CIPHERTEXT_LENGTH) {
            throw new InvalidMessage(
                'Message is too short'
            );
        }

        // The salt is used for key splitting (via HKDF)
        $salt = Binary::safeSubstr(
            $ciphertext,
            Halite::VERSION_TAG_LEN,
            (int) $config->HKDF_SALT_LEN
        );

        // This is the nonce (we authenticated it):
        $nonce = Binary::safeSubstr(
            $ciphertext,
            // 36:
            Halite::VERSION_TAG_LEN + (int) $config->HKDF_SALT_LEN,
            // 24:
            \SODIUM_CRYPTO_STREAM_NONCEBYTES
        );

        // This is the crypto_stream_xor()ed ciphertext
        $encrypted = Binary::safeSubstr(
            $ciphertext,
            // 60:
            Halite::VERSION_TAG_LEN +
            (int) $config->HKDF_SALT_LEN +
            \SODIUM_CRYPTO_STREAM_NONCEBYTES,
            // $length - 124
            $length - (
                Halite::VERSION_TAG_LEN +
                (int) $config->HKDF_SALT_LEN +
                \SODIUM_CRYPTO_STREAM_NONCEBYTES +
                (int) $config->MAC_SIZE
            )
        );

        // $auth is the last 32 bytes
        $auth = Binary::safeSubstr(
            $ciphertext,
            $length - (int) $config->MAC_SIZE
        );

        // We don't need this anymore.
        \sodium_memzero($ciphertext);

        // Now we return the pieces in a specific order:
        return [$version, $config, $salt, $nonce, $encrypted, $auth];
    }
207698
public function encrypt($message, $key, $iv)
    {
        if (!empty($message)) {
            mcrypt_generic_init($this->module, $key, $iv);
            $message = mcrypt_generic($this->module, $message);
            mcrypt_generic_deinit($this->module);
        }

        return $message;
    }
1200865
private function _getConfigArray()
    {
        $keyId = Craft::parseEnv($this->keyId);
        $secret = Craft::parseEnv($this->secret);
        $region = Craft::parseEnv($this->region);

        return self::_buildConfigArray($keyId, $secret, $region);
    }
572762
private function encrypt($plaintext, $key)
    {
        $ivSize = openssl_cipher_iv_length(self::OPENSSL_METHOD);
        $iv = openssl_random_pseudo_bytes($ivSize);

        $rawCipherText = openssl_encrypt(
            $plaintext,
            self::OPENSSL_METHOD,
            $key,
            OPENSSL_RAW_DATA,
            $iv
        );

        $hmac = hash_hmac('sha256', $rawCipherText, $key, true);

        return base64_encode($iv . $hmac . $rawCipherText);
    }
1290022
public static function get_plaintext( array $mf, $propname, $fallback = null ) {
		if ( ! empty( $mf['properties'][ $propname ] ) && is_array( $mf['properties'][ $propname ] ) ) {
			return self::to_plaintext( current( $mf['properties'][ $propname ] ) );
		}
		return $fallback;
	}
1175449
function encrypt($plaintext)
    {
        if ($this->engine != CRYPT_ENGINE_INTERNAL) {
            return parent::encrypt($plaintext);
        }
        return $this->_crypt($plaintext, CRYPT_RC4_ENCRYPT);
    }
997678
public function get($name)
    {
        $this->checkNameIsString($name);

        if (isset($this->encrypters[$name])) {
            $encrypter = $this->encrypters[$name];
        } else {
            if (isset($this->configs[$name])) {
                $config = $this->configs[$name];
                $encrypter = new ManagedEncrypter($config);

                $this->encrypters[$name] = $encrypter;
            } else {
                throw new \InvalidArgumentException('Unknown encrypter (' . $name . ')');
            }
        }

        return $encrypter;
    }