diff options
author | Viacheslav Hletenko <v.gletenko@vyos.io> | 2024-11-19 17:44:58 +0000 |
---|---|---|
committer | Viacheslav Hletenko <v.gletenko@vyos.io> | 2024-11-21 13:34:51 +0000 |
commit | 5c7647bcc242d4b26cd9afdde1f084ef93916727 (patch) | |
tree | f87fe803bce58e2245b7273cf95c8ffc69e6f734 /python | |
parent | 8f76c96cb4d7132b7654aa5f37e8ab49fa2e137a (diff) | |
download | vyos-1x-5c7647bcc242d4b26cd9afdde1f084ef93916727.tar.gz vyos-1x-5c7647bcc242d4b26cd9afdde1f084ef93916727.zip |
T264: IPsec add base64 encoded secret-type feature
Add the ability to configure base64 encoded passwords for
VPN IPSec site-to-site peers
authentication psk PSK secret 'xxxxx=='
authentication psk PSK secret-type <base64|plaintext>
Diffstat (limited to 'python')
-rw-r--r-- | python/vyos/utils/convert.py | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/python/vyos/utils/convert.py b/python/vyos/utils/convert.py index dd4266f57..2f587405d 100644 --- a/python/vyos/utils/convert.py +++ b/python/vyos/utils/convert.py @@ -235,3 +235,29 @@ def convert_data(data) -> dict | list | tuple | str | int | float | bool | None: # which cannot be converted to JSON # for example: complex | range | memoryview return + + +def encode_to_base64(input_string): + """ + Encodes a given string to its base64 representation. + + Args: + input_string (str): The string to be encoded. + + Returns: + str: The base64-encoded version of the input string. + + Example: + input_string = "Hello, World!" + encoded_string = encode_to_base64(input_string) + print(encoded_string) # Output: SGVsbG8sIFdvcmxkIQ== + """ + import base64 + # Convert the string to bytes + byte_string = input_string.encode('utf-8') + + # Encode the byte string to base64 + encoded_string = base64.b64encode(byte_string) + + # Decode the base64 bytes back to a string + return encoded_string.decode('utf-8') |