src/Secrets.php
static public function encryptString($plaintext_string, $key_name) {
        $kms = self::getService();
        $base64_encoded_json = base64_encode($plaintext_string);
        $request = new \Google_Service_CloudKMS_EncryptRequest();
        $request->setPlaintext($base64_encoded_json);
        $response = $kms->projects_locations_keyRings_cryptoKeys->encrypt(
            $key_name,
            $request
        );
        return $response['ciphertext'];
    }
static public function encryptString($plaintext_string, $key_name) {
        $kms = self::getService();
        $base64_encoded_json = base64_encode($plaintext_string);
        $request = new \Google_Service_CloudKMS_EncryptRequest();
        $request->setPlaintext($base64_encoded_json);
        $response = $kms->projects_locations_keyRings_cryptoKeys->encrypt(
            $key_name,
            $request
        );
        return $response['ciphertext'];
    }
static public function encryptString ( $ plaintext_string , $ key_name ) { $ kms = self :: getService ( ) ; $ base64_encoded_json = base64_encode ( $ plaintext_string ) ; $ request = new \ Google_Service_CloudKMS_EncryptRequest ( ) ; $ request -> setPlaintext ( $ base64_encoded_json ) ; $ response = $ kms -> projects_locations_keyRings_cryptoKeys -> encrypt ( $ key_name , $ request ) ; return $ response [ 'ciphertext' ] ; }
Encrypts a string and returns the base64_encoded response from KMS.

@param $string
@param $key_name
@return mixed
Encrypts a string and returns the base64_encoded response from KMS .