summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorChristian Breunig <christian@breunig.cc>2024-11-26 07:49:51 +0100
committerGitHub <noreply@github.com>2024-11-26 07:49:51 +0100
commitf3a46fc296a488b3748182288b1cff4df39c4971 (patch)
tree5694564e12f2b2b04813a32419917d1526178001 /python
parentefd86e5cbaf2cae68e431b83f6ca6c0093672e89 (diff)
parent5c7647bcc242d4b26cd9afdde1f084ef93916727 (diff)
downloadvyos-1x-f3a46fc296a488b3748182288b1cff4df39c4971.tar.gz
vyos-1x-f3a46fc296a488b3748182288b1cff4df39c4971.zip
Merge pull request #4198 from sever-sever/T264
T264: IPsec add base64 encoded secret-type feature
Diffstat (limited to 'python')
-rw-r--r--python/vyos/utils/convert.py26
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')