1616package org .springframework .vault .core ;
1717
1818import java .util .ArrayList ;
19+ import java .util .Base64 ;
1920import java .util .Collections ;
2021import java .util .LinkedHashMap ;
2122import java .util .List ;
2627
2728import org .springframework .lang .Nullable ;
2829import org .springframework .util .Assert ;
29- import org .springframework .util .Base64Utils ;
3030import org .springframework .util .ObjectUtils ;
3131import org .springframework .util .StringUtils ;
3232import org .springframework .vault .VaultException ;
@@ -168,7 +168,7 @@ public String encrypt(String keyName, String plaintext) {
168168
169169 Map <String , String > request = new LinkedHashMap <>();
170170
171- request .put ("plaintext" , Base64Utils .encodeToString (plaintext .getBytes ()));
171+ request .put ("plaintext" , Base64 . getEncoder () .encodeToString (plaintext .getBytes ()));
172172
173173 return (String ) this .vaultOperations .write (String .format ("%s/encrypt/%s" , this .path , keyName ), request )
174174 .getRequiredData ()
@@ -195,7 +195,7 @@ public String encrypt(String keyName, byte[] plaintext, VaultTransitContext tran
195195
196196 Map <String , String > request = new LinkedHashMap <>();
197197
198- request .put ("plaintext" , Base64Utils .encodeToString (plaintext ));
198+ request .put ("plaintext" , Base64 . getEncoder () .encodeToString (plaintext ));
199199
200200 applyTransitOptions (transitContext , request );
201201
@@ -216,7 +216,7 @@ public List<VaultEncryptionResult> encrypt(String keyName, List<Plaintext> batch
216216
217217 Map <String , String > vaultRequest = new LinkedHashMap <>(2 );
218218
219- vaultRequest .put ("plaintext" , Base64Utils .encodeToString (request .getPlaintext ()));
219+ vaultRequest .put ("plaintext" , Base64 . getEncoder () .encodeToString (request .getPlaintext ()));
220220
221221 if (request .getContext () != null ) {
222222 applyTransitOptions (request .getContext (), vaultRequest );
@@ -246,7 +246,7 @@ public String decrypt(String keyName, String ciphertext) {
246246 .getRequiredData ()
247247 .get ("plaintext" );
248248
249- return new String (Base64Utils . decodeFromString (plaintext ));
249+ return new String (Base64 . getDecoder (). decode (plaintext ));
250250 }
251251
252252 @ Override
@@ -278,7 +278,7 @@ public byte[] decrypt(String keyName, String ciphertext, VaultTransitContext tra
278278 .getRequiredData ()
279279 .get ("plaintext" );
280280
281- return Base64Utils . decodeFromString (plaintext );
281+ return Base64 . getDecoder (). decode (plaintext );
282282 }
283283
284284 @ Override
@@ -360,7 +360,9 @@ public Hmac getHmac(String keyName, VaultHmacRequest hmacRequest) {
360360 Map <String , Object > request = new LinkedHashMap <>(3 );
361361 PropertyMapper mapper = PropertyMapper .get ();
362362
363- mapper .from (hmacRequest .getPlaintext ()::getPlaintext ).as (Base64Utils ::encodeToString ).to ("input" , request );
363+ mapper .from (hmacRequest .getPlaintext ()::getPlaintext )
364+ .as (Base64 .getEncoder ()::encodeToString )
365+ .to ("input" , request );
364366 mapper .from (hmacRequest ::getAlgorithm ).whenHasText ().to ("algorithm" , request );
365367 mapper .from (hmacRequest ::getKeyVersion ).whenNonNull ().to ("key_version" , request );
366368
@@ -391,7 +393,9 @@ public Signature sign(String keyName, VaultSignRequest signRequest) {
391393 Map <String , Object > request = new LinkedHashMap <>(3 );
392394 PropertyMapper mapper = PropertyMapper .get ();
393395
394- mapper .from (signRequest .getPlaintext ()::getPlaintext ).as (Base64Utils ::encodeToString ).to ("input" , request );
396+ mapper .from (signRequest .getPlaintext ()::getPlaintext )
397+ .as (Base64 .getEncoder ()::encodeToString )
398+ .to ("input" , request );
395399 mapper .from (signRequest ::getHashAlgorithm ).whenHasText ().to ("hash_algorithm" , request );
396400 mapper .from (signRequest ::getSignatureAlgorithm ).whenHasText ().to ("signature_algorithm" , request );
397401
@@ -423,7 +427,7 @@ public SignatureValidation verify(String keyName, VaultSignatureVerificationRequ
423427 PropertyMapper mapper = PropertyMapper .get ();
424428
425429 mapper .from (verificationRequest .getPlaintext ()::getPlaintext )
426- .as (Base64Utils ::encodeToString )
430+ .as (Base64 . getEncoder () ::encodeToString )
427431 .to ("input" , request );
428432 mapper .from (verificationRequest ::getHmac ).whenNonNull ().as (Hmac ::getHmac ).to ("hmac" , request );
429433 mapper .from (verificationRequest ::getSignature )
@@ -447,11 +451,11 @@ public SignatureValidation verify(String keyName, VaultSignatureVerificationRequ
447451 private static void applyTransitOptions (VaultTransitContext context , Map <String , String > request ) {
448452
449453 if (!ObjectUtils .isEmpty (context .getContext ())) {
450- request .put ("context" , Base64Utils .encodeToString (context .getContext ()));
454+ request .put ("context" , Base64 . getEncoder () .encodeToString (context .getContext ()));
451455 }
452456
453457 if (!ObjectUtils .isEmpty (context .getNonce ())) {
454- request .put ("nonce" , Base64Utils .encodeToString (context .getNonce ()));
458+ request .put ("nonce" , Base64 . getEncoder () .encodeToString (context .getNonce ()));
455459 }
456460 }
457461
@@ -517,7 +521,7 @@ private static VaultDecryptionResult getDecryptionResult(Map<String, String> dat
517521
518522 if (StringUtils .hasText (data .get ("plaintext" ))) {
519523
520- byte [] plaintext = Base64Utils . decodeFromString (data .get ("plaintext" ));
524+ byte [] plaintext = Base64 . getDecoder (). decode (data .get ("plaintext" ));
521525 return new VaultDecryptionResult (Plaintext .of (plaintext ).with (ciphertext .getContext ()));
522526 }
523527
0 commit comments