Decodes a Base64 encoded string back into a normal string. :param base64_string: str - The Base64 encoded string to be decoded. :return: str - The decoded string.
(base64_string)
| 27 | |
| 28 | |
| 29 | def decode_base64_to_text(base64_string): |
| 30 | """ |
| 31 | Decodes a Base64 encoded string back into a normal string. |
| 32 | |
| 33 | :param base64_string: str - The Base64 encoded string to be decoded. |
| 34 | :return: str - The decoded string. |
| 35 | """ |
| 36 | |
| 37 | # Add padding characters to the base64 string if necessary |
| 38 | padding = "=" * (-len(base64_string) % 4) |
| 39 | base64_string_with_padding = base64_string + padding |
| 40 | |
| 41 | # Encode these bytes and then decode the result to get a string |
| 42 | base64_bytes = base64_string_with_padding.encode("utf-8") |
| 43 | |
| 44 | # Decode the base64 bytes and then decode the result to get a string |
| 45 | input_bytes = base64.b64decode(base64_bytes) |
| 46 | input_string = input_bytes.decode("utf-8") |
| 47 | |
| 48 | return input_string |
no test coverage detected