blob: 4bc514ac2867de84f44f17f8fbd2c0b325bdc132 [file] [log] [blame]
James E. Blair01f83b72017-03-15 13:03:40 -07001#!/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 Boylan0996ab22017-10-19 11:03:10 -070015import base64
James E. Blair01f83b72017-03-15 13:03:40 -070016import sys
17import os
18
James E. Blairbf1a4f22017-03-17 10:59:37 -070019from zuul.lib import encryption
James E. Blair01f83b72017-03-15 13:03:40 -070020
21FIXTURE_DIR = os.path.join(os.path.dirname(__file__),
22 'fixtures')
23
24
25def main():
26 private_key_file = os.path.join(FIXTURE_DIR, 'private.pem')
27 with open(private_key_file, "rb") as f:
James E. Blairbf1a4f22017-03-17 10:59:37 -070028 private_key, public_key = \
29 encryption.deserialize_rsa_keypair(f.read())
James E. Blair01f83b72017-03-15 13:03:40 -070030
Clark Boylan0996ab22017-10-19 11:03:10 -070031 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. Blair01f83b72017-03-15 13:03:40 -070035
David Shrewsbury699a6b22017-05-19 09:38:36 -040036
James E. Blair01f83b72017-03-15 13:03:40 -070037if __name__ == '__main__':
38 main()