[bug] don't stringify value before encryption

This commit is contained in:
NicolasCantu 2025-06-06 11:23:20 +02:00
parent e72e0d9fe8
commit 815b640a27

View File

@ -1186,8 +1186,7 @@ pub fn create_new_process(
for (field, plain_value) in private_data.iter() { for (field, plain_value) in private_data.iter() {
let hash = pcd_commitment.get(field).ok_or(anyhow::Error::msg("Missing commitment"))?; let hash = pcd_commitment.get(field).ok_or(anyhow::Error::msg("Missing commitment"))?;
let key = generate_key(&mut rng); let key = generate_key(&mut rng);
let serialized = serde_json::to_string(plain_value)?; let cipher = encrypt_with_key(&key, plain_value.as_slice())?;
let cipher = encrypt_with_key(&key, serialized.as_bytes())?;
new_state.keys.insert(field.to_owned(), key); new_state.keys.insert(field.to_owned(), key);
encrypted_data.insert(hash.to_lower_hex_string(), cipher.to_lower_hex_string()); encrypted_data.insert(hash.to_lower_hex_string(), cipher.to_lower_hex_string());
} }
@ -1674,7 +1673,7 @@ pub fn is_child_role(parent_roles: String, child_roles: String) -> ApiResult<()>
} }
#[wasm_bindgen] #[wasm_bindgen]
pub fn decrypt_data(key: &[u8], data: &[u8]) -> ApiResult<String> { pub fn decrypt_data(key: &[u8], data: &[u8]) -> ApiResult<Vec<u8>> {
let mut key_buf = [0u8; 32]; let mut key_buf = [0u8; 32];
if key.len() != 32 { if key.len() != 32 {