Skip to content

Create columnencryption #370

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions scripts/columnencryption
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from google.cloud import kms_v1
from google.cloud.kms_v1 import enums
from google.protobuf import field_mask_pb2
import base64

# Initialize the KMS client
client = kms_v1.KeyManagementServiceClient()

# Set your KMS key name
kms_key_name = "projects/model-height-439805-h4/locations/global/keyRings/my-key-ring/cryptoKeys/my-crypto-key"

# The data you want to encrypt (SSN in this case)
data_to_encrypt = "123-45-6789"

# Encrypt the data
response = client.encrypt(name=kms_key_name, plaintext=data_to_encrypt.encode("utf-8"))

# The encrypted data will be in the 'ciphertext' field
encrypted_data = base64.b64encode(response.ciphertext).decode('utf-8')

# Print the encrypted data (you can now store this in BigQuery)
print(f"Encrypted Data: {encrypted_data}")