对称加密
Sapphire.encrypt 与 Sapphire.decrypt 封装 Deoxys-II 认证对称加密算法。当你需要用调用者提供的密钥加密数据时用它们——例如跨合约边界传递加密 blob,或存储用户特定的密文。
对于"合约保存自己的秘密",一般不需要这些——加密合约存储自动处理。
签名
function encrypt(
bytes32 key,
bytes32 nonce,
bytes memory plaintext,
bytes memory additionalData
) internal view returns (bytes memory);
function decrypt(
bytes32 key,
bytes32 nonce,
bytes memory ciphertext,
bytes memory additionalData
) internal view returns (bytes memory);
key——32 字节对称密钥。nonce——每次加密唯一的 32 字节值。同一 key 下不得重复。plaintext/ciphertext