Fix for remote policy filtering
[optf/osdf.git] / osdf / cmd / encryptionUtil.py
1 #
2 # -------------------------------------------------------------------------
3 #   Copyright (c) 2015-2018 AT&T Intellectual Property
4 #
5 #   Licensed under the Apache License, Version 2.0 (the "License");
6 #   you may not use this file except in compliance with the License.
7 #   You may obtain a copy of the License at
8 #
9 #       http://www.apache.org/licenses/LICENSE-2.0
10 #
11 #   Unless required by applicable law or agreed to in writing, software
12 #   distributed under the License is distributed on an "AS IS" BASIS,
13 #   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 #   See the License for the specific language governing permissions and
15 #   limitations under the License.
16 #
17 # -------------------------------------------------------------------------
18 #
19 import sys
20 from osdf.utils import cipherUtils
21
22
23 def main():
24
25     if len(sys.argv) != 4:
26         print("Invalid input - usage --> (options(encrypt/decrypt) input-value with-key)")
27         return
28
29     enc_dec = sys.argv[1]
30     valid_option_values = ['encrypt', 'decrypt']
31     if enc_dec not in valid_option_values:
32         print("Invalid input - usage --> (options(encrypt/decrypt) input-value with-key)")
33         print("Option value can only be one of {}".format(valid_option_values))
34         print("You entered '{}'".format(enc_dec))
35         return
36
37     input_string = sys.argv[2]
38     with_key = sys.argv[3]
39
40     print("You've requested '{}' to be '{}ed' using key '{}'".format(input_string, enc_dec, with_key))
41     print("You can always perform the reverse operation (encrypt/decrypt) using the same key"
42           "to be certain you get the same results back'")
43
44     util = cipherUtils.AESCipher.get_instance(with_key)
45     if enc_dec.lower() == 'encrypt':
46         result = util.encrypt(input_string)
47     else:
48         result = util.decrypt(input_string)
49
50     print("Your resultt: {}".format(result))