James E. Blair | 01f83b7 | 2017-03-15 13:03:40 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | # Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 4 | # not use this file except in compliance with the License. You may obtain |
| 5 | # a copy of the License at |
| 6 | # |
| 7 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | # |
| 9 | # Unless required by applicable law or agreed to in writing, software |
| 10 | # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 11 | # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 12 | # License for the specific language governing permissions and limitations |
| 13 | # under the License. |
| 14 | |
Clark Boylan | 0996ab2 | 2017-10-19 11:03:10 -0700 | [diff] [blame] | 15 | import base64 |
James E. Blair | 01f83b7 | 2017-03-15 13:03:40 -0700 | [diff] [blame] | 16 | import sys |
| 17 | import os |
| 18 | |
James E. Blair | bf1a4f2 | 2017-03-17 10:59:37 -0700 | [diff] [blame] | 19 | from zuul.lib import encryption |
James E. Blair | 01f83b7 | 2017-03-15 13:03:40 -0700 | [diff] [blame] | 20 | |
| 21 | FIXTURE_DIR = os.path.join(os.path.dirname(__file__), |
| 22 | 'fixtures') |
| 23 | |
| 24 | |
| 25 | def main(): |
| 26 | private_key_file = os.path.join(FIXTURE_DIR, 'private.pem') |
| 27 | with open(private_key_file, "rb") as f: |
James E. Blair | bf1a4f2 | 2017-03-17 10:59:37 -0700 | [diff] [blame] | 28 | private_key, public_key = \ |
| 29 | encryption.deserialize_rsa_keypair(f.read()) |
James E. Blair | 01f83b7 | 2017-03-15 13:03:40 -0700 | [diff] [blame] | 30 | |
Clark Boylan | 0996ab2 | 2017-10-19 11:03:10 -0700 | [diff] [blame] | 31 | plaintext = sys.argv[1].encode('utf-8') |
| 32 | |
| 33 | ciphertext = encryption.encrypt_pkcs1_oaep(plaintext, public_key) |
| 34 | print(base64.b64encode(ciphertext).decode('utf-8')) |
James E. Blair | 01f83b7 | 2017-03-15 13:03:40 -0700 | [diff] [blame] | 35 | |
David Shrewsbury | 699a6b2 | 2017-05-19 09:38:36 -0400 | [diff] [blame] | 36 | |
James E. Blair | 01f83b7 | 2017-03-15 13:03:40 -0700 | [diff] [blame] | 37 | if __name__ == '__main__': |
| 38 | main() |