Converts a given string into its corresponding MD5 hash. This function encodes the input string using UTF-8 and computes the MD5 hash, returning the result as a 32-character hexadecimal string. Args: text (str): The input string to be hashed. Returns: str: The
(text: str)
| 124 | |
| 125 | |
| 126 | def str_to_md5(text: str) -> str: |
| 127 | """ |
| 128 | Converts a given string into its corresponding MD5 hash. |
| 129 | |
| 130 | This function encodes the input string using UTF-8 and computes the MD5 hash, |
| 131 | returning the result as a 32-character hexadecimal string. |
| 132 | |
| 133 | Args: |
| 134 | text (str): The input string to be hashed. |
| 135 | |
| 136 | Returns: |
| 137 | str: The MD5 hash of the input string, represented as a hexadecimal string. |
| 138 | |
| 139 | Example: |
| 140 | >>> str_to_md5("hello world") |
| 141 | '5eb63bbbe01eeed093cb22bb8f5acdc3' |
| 142 | """ |
| 143 | text_bytes = text.encode('utf-8') |
| 144 | md5_hash = hashlib.md5(text_bytes) |
| 145 | return md5_hash.hexdigest() |
| 146 | |
| 147 | |
| 148 | def escape_yaml_string(text: str) -> str: |