bcb-0026
1.000
Proposed solution
```python
import base64
from cryptography.fernet import Fernet
def task_func(message, encryption_key):
"""
Encrypts a message with a symmetric encryption key using Fernet encryption, and then encode the
encrypted message using base64.
Parameters:
message (str): The message to be encrypted and encoded.
encryption_key (str): The key used for symmetric encryption. It should be a string, which will
be encoded to bytes, then URL-safe base64 encoded to conform to the requirements
for Fernet (32 bytes after encoding).
Returns:
str: The base64 encoded encrypted message. The message is first encrypted using Fernet encryption,
then the result is base64 encoded.
Requirements:
- base64
- cryptography.fernet
Example:
>>> encrypted_message = task_func('Hello, World!', '01234567890123456789012345678901')
>>> isinstance(encrypted_message, str)
True
"""
# Convert the encryption key to bytes
key_bytes = encryption_key.encode('utf-8')
# Create a Fernet instance with the key
f = Fernet(base64.urlsafe_b64encode(key_bytes))
# Encrypt the message
encrypted_message = f.encrypt(message.encode('utf-8'))
# Base64 encode the encrypted message
encoded_message = base64.b64encode(encrypted_message).decode('utf-8')
return encoded_message
```Test output (stdout)
...... [100%] 6 passed in 0.04s
System prompt
You are an expert programmer. Solve the task exactly as specified. Output your solution as fenced code blocks using the required file name(s) and the exact function/type signatures requested. Prefer correctness; do not include prose outside code unless asked.