Skip to main content

Appendix. Encrypt database user password

This document provides guidance on how to encrypt the database user password.

caution
  • The user.password field must be populated with an encrypted value for the request to be processed successfully.

Prerequisites

Example Python code for encrypting the DB user password

Below is a Python code example for encrypting the database user password.
Run the code example using the provided public key file, and enter the desired password to receive an encrypted output.
Use the encrypted result as the value of the user.password field when creating an instance group or cluster.

Code Example: encrypt database user password
memstore_pub_key.pem file
-----BEGIN RSA PUBLIC KEY-----
MIIBCgKCAQEAr4mgZ4SFzTEtgdh3WZSWgMF/l6PhR9gdeq8jwP2BlyWW06UgZPhL
jKi+o3rbCWtpARtpn9ik1DKfG2ZQOempPlBv70JZMqzuvZcDueQdihRS2isCq5rS
6V40S8eq3UIi80UVS6U3hIFA0y3uNMREW1ny5H4nw2IQUIXm7W2KSIc57JE4uIu9
cmNvG1uwbBuj49JUUmHIgxd9FYURxeVyuwc5CO9uA5tXTYPePtOSXQs4SnoEJK+o
t+EQMBpokaUe/UYHjr4z68Lz8V+3r62bkfFr5dN5MsVpAeOMHp0az3H2uIfU8JQa
6FNZ7BJcuEP8ezEL6GQUkLJ8P0tQQ/5spQIDAQAB
-----END RSA PUBLIC KEY-----
Example: Encrypt DB user password
#!/usr/bin/env python3
import sys
from Cryptodome.Cipher import PKCS1_v1_5
from Cryptodome.PublicKey import RSA
import base64

# Read the public key from a file
pubkey_file = open("memstore_pub_key.pem", 'r')
pubkey = pubkey_file.read()
pubkey_file.close()

# Enter DBUser_Password
msg = input("Enter KC memstore DBUser Password: ")

# Create RSA key using the public key
key = RSA.importKey(pubkey)
cipher = PKCS1_v1_5.new(key)
cipher_msg = cipher.encrypt(msg.encode())
encode_msg = base64.b64encode(cipher_msg)
encryptedMsg = encode_msg.decode('utf-8')

# Print the encrypted password
print("Encrypted text : ", encryptedMsg )
Result Example
Example output of script execution
test@test-macbook ~ % ./memstore_dbuser_password_encrypt.py
Enter KC memstore DBUser Password: kcmemstore123$
Encrypted text : QEmUQjAZqAHEBpdiVlok/9l6fDKM6f0Q60S35pQmB/KILKf5c3SrcbWv55H1fu+EevKVeA1cCNzgJxz0rMMdtgPE5zoBX2c6cQoUqsUZ0g9e3pAg3WEt70HxMfxyVy1WY2TNe2uic6l0+Nx+cIdIBJcBpJ+OQQTrSdCDDLUQRnrnhuPqnyXvdgP0tXjgpKzmfLsjebJS9Wa+8TY9ee6oBLx5F2+XMjDFapw4hXfbSwKUWDFK+czTa11zwYDpMdwmISVWwX9e77rfZg7f9sfsd2+lzbFj52LORf1CF2DGzgqP3I3xSf+0KiekwwAy3Kca5EHkyqK7mWeXMeKk7qnWjQ==