I am trying to encrypt confidential and sensitive data using the Google Cloud Key Management Service (KMS) python API. I noticed in every iteration after the encryption that the same key for the exact input text generates different encrypted ciphertext. I mean, for the same input text, I am getting different encrypted ciphertext.
My question is,
- why the encrypted ciphertext got changed? How to get the same encrypted ciphertext/value for the same input?
- How the control the length of encrypted ciphertext?
Here is the python code I used
from google.cloud import kms
client = kms.KeyManagementServiceClient()
name = 'projects/sandbox/locations/global/keyRings/encryptdecrypt-keyring/cryptoKeys/encryptdecrypt-key_v01/cryptoKeyVersions/1' #CryptoKey info
plaintext = b'hello123' # The data to encrypt
enc1=client.encrypt(request={'name': name, 'plaintext': plaintext})
Ref:
IV, or Initialization Vector prevents the same plaintext from generating the same cyphertext. en.wikipedia.org/wiki/Initialization_vector - John Hanley