-
use orion::aead as crypto;
pub fn enrypt_string(string: String, password: String) -> Result<Vec<u8>, orion::errors::UnknownCryptoError>{
println!("{:?}", password.as_bytes());
let passphrase = crypto::SecretKey::from_slice(password.as_bytes()).expect("Failed to encrypt password");
println!("{:?} {:?}", passphrase, string.as_bytes());
let ciphertext = crypto::seal(&passphrase, &string.as_bytes()).expect("Failed to encrypt text");
Ok(ciphertext)
} Panics at
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 11 replies
-
I changed the secretkey method to default() and it works now, but I want a user inputted password |
Beta Was this translation helpful? Give feedback.
-
Hi! If you take a peek at the errors documentation, you'll see that the first one says that the In practice, please note that using user-passwords directly to encrypt data is not secure. You can use Don't hesitate to let us know if there's anything else! |
Beta Was this translation helpful? Give feedback.
Hi!
If you take a peek at the errors documentation, you'll see that the first one says that the
secret_key
must be 32 bytes. The password you use here is however only 14 bytes. You can use the.len()
function on aSecretKey
instance to check if it is upheld.default()
randomly generates 32 bytes, which is why it works.In practice, please note that using user-passwords directly to encrypt data is not secure. You can use
orion::kdf
to "stretch" the password before using it for encryption. There is also an example in that module for this exact use-case.Don't hesitate to let us know if there's anything else!