热门角色不仅是灵感来源,更是你的效率助手。通过精挑细选的角色提示词,你可以快速生成高质量内容、提升创作灵感,并找到最契合你需求的解决方案。让创作更轻松,让价值更直接!
我们根据不同用户需求,持续更新角色库,让你总能找到合适的灵感入口。
根据指定数据类别推荐适合的加密方法,提供技术性解答。
建议采用“AEAD + 信封加密”的方案,结合传输层加密,专门针对数据管道的中间数据(临时文件、分片、缓存、消息负载、临时表等)的低延迟、短生命周期特点。
一、总体方案
二、关键实现要点
三、示例:Python(AWS KMS + AES-GCM 的信封加密)
加密
示例代码(简化):
from boto3 import client from cryptography.hazmat.primitives.ciphers.aead import AESGCM import os, json
kms = client("kms", region_name="us-east-1") kms_key_id = "arn:aws:kms:...:key/..." # KEK
def encrypt_blob(plaintext: bytes, aad_meta: dict): # 1) 生成 DEK(明文+密文) resp = kms.generate_data_key(KeyId=kms_key_id, KeySpec="AES_256") dek_plain = resp["Plaintext"] # bytes dek_encrypted = resp["CiphertextBlob"] # bytes
try:
# 2) 随机 12 字节 nonce(GCM 推荐)
nonce = os.urandom(12)
aad = json.dumps(aad_meta, separators=(",", ":")).encode("utf-8")
# 3) AEAD 加密
aesgcm = AESGCM(dek_plain)
ciphertext = aesgcm.encrypt(nonce, plaintext, aad)
return {
"ciphertext": ciphertext,
"nonce": nonce,
"aad": aad_meta,
"dek_encrypted": dek_encrypted, # 与数据一起存储
}
finally:
# 4) 清除明文 DEK
dek_plain = None
def decrypt_blob(package: dict) -> bytes: # 解密 DEK dek_plain = kms.decrypt(CiphertextBlob=package["dek_encrypted"])["Plaintext"] try: aesgcm = AESGCM(dek_plain) aad = json.dumps(package["aad"], separators=(",", ":")).encode("utf-8") return aesgcm.decrypt(package["nonce"], package["ciphertext"], aad) finally: dek_plain = None
四、在常见数据管道组件中的应用
五、校验清单
该方案在主流云与本地环境均易实施,兼顾安全性、完整性与性能,适合数据管道中间数据的加密需求。
Scope
Recommendation summary
Details
Python example (Argon2id):
Dependencies: argon2-cffi, secrets
from argon2 import PasswordHasher from argon2.low_level import Type import hmac, hashlib, secrets
ph = PasswordHasher( time_cost=3, memory_cost=65536, # 64 MiB parallelism=2, hash_len=32, type=Type.ID )
PEPPER = secrets.token_bytes(32) # Load from a secret manager/KMS in production
def hash_password(password: str) -> str: # Apply pepper via HMAC to avoid length leaks mac = hmac.new(PEPPER, password.encode('utf-8'), hashlib.sha256).digest() return ph.hash(mac)
def verify_password(password: str, stored_hash: str) -> bool: mac = hmac.new(PEPPER, password.encode('utf-8'), hashlib.sha256).digest() try: ph.verify(stored_hash, mac) return True except Exception: return False
Python example (AES‑GCM with AWS KMS envelope encryption):
Dependencies: boto3, cryptography
import os, json, base64 from cryptography.hazmat.primitives.ciphers.aead import AESGCM import boto3
kms = boto3.client('kms')
def encrypt_secret(plaintext: bytes, aad: bytes = b'') -> dict: # 1) Generate a random DEK from KMS resp = kms.generate_data_key(KeyId='arn:aws:kms:region:acct:key/KEY_ID', KeySpec='AES_256') dek_plain = resp['Plaintext'] # bytes dek_encrypted = resp['CiphertextBlob'] # bytes (wrapped by KMS)
try:
# 2) Encrypt with AES‑GCM
aesgcm = AESGCM(dek_plain)
nonce = os.urandom(12)
ct = aesgcm.encrypt(nonce, plaintext, aad)
return {
'ciphertext_b64': base64.b64encode(ct).decode(),
'nonce_b64': base64.b64encode(nonce).decode(),
'dek_wrapped_b64': base64.b64encode(dek_encrypted).decode(),
'aad_b64': base64.b64encode(aad).decode(),
'kms_key_id': resp['KeyId'],
}
finally:
# Zeroize DEK from memory
dek_plain = b'\x00' * len(dek_plain)
def decrypt_secret(record: dict) -> bytes: dek_encrypted = base64.b64decode(record['dek_wrapped_b64']) nonce = base64.b64decode(record['nonce_b64']) ct = base64.b64decode(record['ciphertext_b64']) aad = base64.b64decode(record['aad_b64'])
# 1) Unwrap DEK
resp = kms.decrypt(CiphertextBlob=dek_encrypted)
dek_plain = resp['Plaintext']
try:
# 2) Decrypt with AES‑GCM
aesgcm = AESGCM(dek_plain)
return aesgcm.decrypt(nonce, ct, aad)
finally:
dek_plain = b'\x00' * len(dek_plain)
Notes:
Pitfalls to avoid
This approach provides strong confidentiality and integrity for credentials, with operationally sound key management and rotation aligned to data engineering practices.
推荐方案概要
为何选型
参考架构与实现要点
实现示例:Python 客户端信封加密(AWS KMS + AES-GCM) 说明:示例展示核心流程;生产环境需补充重试、超时、审计、错误处理和密钥缓存。
kms = boto3.client("kms", region_name="ap-southeast-1") KEY_ID = "arn:aws:kms:...:key/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
def envelope_encrypt(plaintext_bytes: bytes, aad: dict): # 1) 生成 DEK(明文与密文) resp = kms.generate_data_key(KeyId=KEY_ID, KeySpec="AES_256") dek_plain = resp["Plaintext"] dek_encrypted = resp["CiphertextBlob"]
# 2) 使用 DEK 进行 AES-256-GCM 加密
aesgcm = AESGCM(dek_plain)
nonce = os.urandom(12) # 96-bit GCM nonce
aad_bytes = json.dumps(aad, separators=(",", ":"), sort_keys=True).encode("utf-8")
ciphertext = aesgcm.encrypt(nonce, plaintext_bytes, aad_bytes) # 包含 tag
# 3) 擦除内存中的明文 DEK(Python 无法完全擦除,这里尽可能覆盖)
del dek_plain
# 4) 返回存储对象
return {
"ciphertext": ciphertext, # 含 tag
"nonce": nonce,
"dek_encrypted": dek_encrypted,
"aad": aad,
"alg": "AES-256-GCM",
"key_id": KEY_ID
}
解密 def envelope_decrypt(obj: dict) -> bytes: dek_plain = kms.decrypt(CiphertextBlob=obj["dek_encrypted"], KeyId=obj["key_id"])["Plaintext"] aesgcm = AESGCM(dek_plain) aad_bytes = json.dumps(obj["aad"], separators=(",", ":"), sort_keys=True).encode("utf-8") plaintext = aesgcm.decrypt(obj["nonce"], obj["ciphertext"], aad_bytes) del dek_plain return plaintext
存储结构(示例) 在表/对象的元数据中存储:
ciphertext: bytes
nonce: bytes
dek_encrypted: bytes (由 KMS 保护)
aad: JSON(tenant_id, table, column, key_version, partition_id)
key_id, alg, created_at
列级加密集成(PostgreSQL 示例思路)
等值查询需求的处理
常见陷阱与校验清单
结论
为产品、技术与合规团队提供一键式的“数据加密方案选型助手”,基于不同数据类别快速生成可落地的加密建议与实施要点,提升合规通过率与客户信任,减少专家依赖与沟通成本;支持多语言输出与标准化结构,便于评审、投标答疑、客户安全问卷及审计材料整理,帮助团队在更短时间内做出清晰、可靠的安全决策。
为不同管道与存储选择加密策略,生成落地步骤与测试清单,缩短上线周期并减少返工。
比较方案的风险与成本,制定密钥管理与轮换制度,推动全公司统一安全标准与持续改进。
对照监管要求输出合规路径与材料清单,辅助通过客户审计、等保测评和招标安全评审。
将模板生成的提示词复制粘贴到您常用的 Chat 应用(如 ChatGPT、Claude 等),即可直接对话使用,无需额外开发。适合个人快速体验和轻量使用场景。
把提示词模板转化为 API,您的程序可任意修改模板参数,通过接口直接调用,轻松实现自动化与批量处理。适合开发者集成与业务系统嵌入。
在 MCP client 中配置对应的 server 地址,让您的 AI 应用自动调用提示词模板。适合高级用户和团队协作,让提示词在不同 AI 工具间无缝衔接。
免费获取高级提示词-优惠即将到期