-
-
Save avoidik/e9864452445d7fa3a3e23fc8c1de206f to your computer and use it in GitHub Desktop.
AWS KMS encryption/decryption using Python/Boto3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import boto3 | |
| import base64 | |
| if __name__ == '__main__': | |
| session = boto3.session.Session() | |
| kms = session.client('kms') | |
| encrypted_password = 'AQECAHjgTiiE7TYRGp5Irf8jQ3HzlaQaHGYgsUJDaavnHcFm0gAAAGswaQYJKoZIhvcNAQcGoFwwWgIBADBVBgkqhkiG9w0BBwEwHgYJYIZIAWUDBAEuMBEEDDwxVQuG0oVwpkU7nQIBEIAoVGk1/wpserb+GVUOzE7PiL/Nr9fTDFKZfpKpF0ip2ct4B2q0Wn6ZZw==' | |
| binary_data = base64.b64decode(encrypted_password) | |
| meta = kms.decrypt(CiphertextBlob=binary_data) | |
| plaintext = meta[u'Plaintext'] | |
| print(plaintext.decode()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import boto3 | |
| import base64 | |
| if __name__ == '__main__': | |
| session = boto3.session.Session() | |
| kms = session.client('kms') | |
| key_id = 'alias/timesheets' | |
| stuff = kms.encrypt(KeyId=key_id, Plaintext='S00pers33kr1t') | |
| binary_encrypted = stuff[u'CiphertextBlob'] | |
| encrypted_password = base64.b64encode(binary_encrypted) | |
| print(encrypted_password.decode()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| boto3==1.4.8 | |
| botocore==1.8.1 | |
| docutils==0.14 | |
| futures==3.1.1 | |
| jmespath==0.9.3 | |
| python-dateutil==2.6.1 | |
| s3transfer==0.1.11 | |
| six==1.11.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment