79277442

Date: 2024-12-13 07:03:04
Score: 0.5
Natty:
Report link

Here is my final solution. That works.

import base64

from pgpy import PGPMessage
from pgpy.constants import CompressionAlgorithm, HashAlgorithm, String2KeyType, SymmetricKeyAlgorithm

origin_data = "hello world, 你好世界"

password = "123456"

message = PGPMessage.new(origin_data)

symmetric_algorithm = SymmetricKeyAlgorithm.AES256
hash_algorithm = HashAlgorithm.SHA1
compression = CompressionAlgorithm.Uncompressed

# s2k mode
s2k_type = String2KeyType.Iterated
# from 65536 to 253952
s2k_count = 65536

enc_message = message.encrypt(
    password,
    cipher=symmetric_algorithm,
    hash=hash_algorithm,
    compression=compression,
    s2k=s2k_type,
    s2k_count=s2k_count,
)
encrypted_bytes = bytes(enc_message)
encrypted_base64 = base64.b64encode(encrypted_bytes).decode("utf-8")
print(f"Encrypted data: {encrypted_base64}")
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: dtldyzb