#blockchain #cosmwasm #cw-aes-gcm-siv

cw-aes-gcm-siv

Helpers to use aes-gcm-siv encryption in CosmWasm contracts

1 stable release

new 1.0.0 Apr 6, 2025

#285 in #cosmwasm

Apache-2.0

14KB
79 lines

cw-aes-gcm-siv

Helpers to use aes-gcm-siv encryption in CosmWasm contracts

Features

  • Serialize and encrypt data
  • Decrypt and deserialize data

Usage

use cosmwasm_std::StdResult;
use cw_aes_gcm_siv::{decrypt_deserialize, serialize_encrypt, EncryptedResponse, Hash};

const MESSAGE: &str = "The secret message";
/// 32 char hex encoded string
pub const ENC_KEY: &str =
	"0000000000000000000000000000000000000000000000000000000000000000";

let enc_key = Hash::parse(ENC_KEY)?;
let timestamp = env.block.time;
let encrypted_response = serialize_encrypt(&enc_key, &timestamp, MESSAGE)?;

let EncryptedResponse { value, timestamp } = encrypted_response;
let message: String = decrypt_deserialize(&enc_key, &timestamp, &value)?;

Licenses

This repo is licensed under Apache 2.0.

Dependencies

~4.5–8MB
~167K SLoC