Normally encryption happens for byte Arrays plainText.
promise = keyVaultClient.encryptAsync(keyId.getBaseIdentifier(), JsonWebKeyEncryptionAlgorithm.RSAOAEP, plainText);
result = promise.get();
cipherText = result.getResult();
Where KeyVaultClient object encrypt byte[] and returns Future.
How to encrypt an object?
You can see soucre code of
encryptAsync
method as below in azure keyvault java sdk:Observe the parameters required in this method, and it's not difficult to find that it needs the parameters of the byte[] type, so you just have to convert object to byte[].
You can refer to the code which mentioned in the SO thread:Java Serializable Object to Byte Array.