@@ -259,21 +259,15 @@ public void addAndRemoveMemberToKeyRingPolicy_addsDisplaysAndRemoves() throws Ex
259
259
260
260
@ Test
261
261
public void encryptDecrypt_encryptsAndDecrypts () throws Exception {
262
- // Get an enabled crypto key version, since the primary version is likely disabled
263
- Snippets .listCryptoKeyVersions (PROJECT_ID , LOCATION_ID , KEY_RING_ID , CRYPTO_KEY_ID );
264
- Matcher matcher = Pattern .compile (".*cryptoKeyVersions/(\\ d+)\" ,\" state\" :\" ENABLED\" .*" ,
265
- Pattern .DOTALL | Pattern .MULTILINE ).matcher (bout .toString ().trim ());
266
- assertTrue (matcher .matches ());
267
- String version = matcher .group (1 );
268
-
269
- byte [] encrypted = CryptFile .encrypt (
270
- PROJECT_ID , KEY_RING_ID , CRYPTO_KEY_ID , version , ENCRYPT_STRING .getBytes ());
262
+ // Encrypt ENCRYPT_STRING with the current primary version.
263
+ byte [] ciphertext = CryptFile .encrypt (
264
+ PROJECT_ID , LOCATION_ID , KEY_RING_ID , CRYPTO_KEY_ID , ENCRYPT_STRING .getBytes ());
271
265
272
- assertThat (new String (encrypted )).isNotEqualTo (ENCRYPT_STRING );
266
+ assertThat (new String (ciphertext )).isNotEqualTo (ENCRYPT_STRING );
273
267
274
- byte [] decrypted = CryptFile .decrypt (
275
- PROJECT_ID , LOCATION_ID , KEY_RING_ID , CRYPTO_KEY_ID , encrypted );
268
+ byte [] plaintext = CryptFile .decrypt (
269
+ PROJECT_ID , LOCATION_ID , KEY_RING_ID , CRYPTO_KEY_ID , ciphertext );
276
270
277
- assertThat (new String (decrypted )).isEqualTo (ENCRYPT_STRING );
271
+ assertThat (new String (plaintext )).isEqualTo (ENCRYPT_STRING );
278
272
}
279
273
}
0 commit comments