src/Secrets.php
static public function encrypt($plaintextFileName, $ciphertextFileName, $key_name = null) {
        $kms = self::getService();
        if (is_null($key_name)) {
            $key_name = self::getDefaultKeyName();
        }

        // Use the KMS API to encrypt the text.
        $encoded = base64_encode(file_get_contents($plaintextFileName));
        $request = new \Google_Service_CloudKMS_EncryptRequest();
        $request->setPlaintext($encoded);
        $response = $kms->projects_locations_keyRings_cryptoKeys->encrypt(
            $key_name,
            $request
        );

        // Write the encrypted text to a file.
        file_put_contents($ciphertextFileName, base64_decode($response['ciphertext']));
        Util::cmdline("\tSaved encrypted text to $ciphertextFileName with key $key_name");
        return true;
    }
static public function encrypt($plaintextFileName, $ciphertextFileName, $key_name = null) {
        $kms = self::getService();
        if (is_null($key_name)) {
            $key_name = self::getDefaultKeyName();
        }

        // Use the KMS API to encrypt the text.
        $encoded = base64_encode(file_get_contents($plaintextFileName));
        $request = new \Google_Service_CloudKMS_EncryptRequest();
        $request->setPlaintext($encoded);
        $response = $kms->projects_locations_keyRings_cryptoKeys->encrypt(
            $key_name,
            $request
        );

        // Write the encrypted text to a file.
        file_put_contents($ciphertextFileName, base64_decode($response['ciphertext']));
        Util::cmdline("\tSaved encrypted text to $ciphertextFileName with key $key_name");
        return true;
    }
static public function encrypt ( $ plaintextFileName , $ ciphertextFileName , $ key_name = null ) { $ kms = self :: getService ( ) ; if ( is_null ( $ key_name ) ) { $ key_name = self :: getDefaultKeyName ( ) ; } // Use the KMS API to encrypt the text. $ encoded = base64_encode ( file_get_contents ( $ plaintextFileName ) ) ; $ request = new \ Google_Service_CloudKMS_EncryptRequest ( ) ; $ request -> setPlaintext ( $ encoded ) ; $ response = $ kms -> projects_locations_keyRings_cryptoKeys -> encrypt ( $ key_name , $ request ) ; // Write the encrypted text to a file. file_put_contents ( $ ciphertextFileName , base64_decode ( $ response [ 'ciphertext' ] ) ) ; Util :: cmdline ( "\tSaved encrypted text to $ciphertextFileName with key $key_name" ) ; return true ; }
Takes an input file and encrypts using the KMS service
and puts it to an outputfile.

@param $plaintextFileName
@param $ciphertextFileName
@return bool
Takes an input file and encrypts using the KMS service and puts it to an outputfile .