You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello.
I only know the definition of Homomorphic Encryption.
And I want to use a cupcake for my personal project.
However, there are only a few simple examples. So, I leave a question here.
I want to use a homomorphic encryption with a string or serde data.
Can you give me some examples code?
And is it right to ask here?
The text was updated successfully, but these errors were encountered:
1tang2bang92
changed the title
Question. using with serde and string
Question. using with serde or string
Jun 27, 2022
I haven't spent a ton of time with the library but here's an example using strings that might help you out. It's extremely similar to the example code. Really all you need to do is convert what you want to encrypt into a vector of bytes, beware that it will be padded with zeros so maybe you should have zero as a termination or some other known way to find the end of your data again:
let fv = cupcake::default();let(pk, sk) = fv.generate_keypair();let msg = "This is my encrypted message.".as_bytes().to_vec();// NOTE: The library seems to pad zeros for you, equivalent to the below, so you don't need to:// msg.resize(fv.n, 0);let ctv = fv.encrypt(&msg,&pk);// Decrypt our message...let pt_actual:Vec<u8> = fv.decrypt(&ctv,&sk);// ...and then cut off all the trailing zeroslet pt_cut = pt_actual
.into_iter().take_while(|v| *v != 0).collect::<Vec<_>>();let decrypted_msg = String::from_utf8(pt_cut).expect("Bad utf8");println!("Decrypted: {:?}", decrypted_msg);
Hello.
I only know the definition of Homomorphic Encryption.
And I want to use a cupcake for my personal project.
However, there are only a few simple examples. So, I leave a question here.
I want to use a homomorphic encryption with a string or serde data.
Can you give me some examples code?
And is it right to ask here?
The text was updated successfully, but these errors were encountered: