Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why do I have to use Plaintext [u8; 384]? #170

Closed
maninkari opened this issue Jun 21, 2022 · 2 comments
Closed

Why do I have to use Plaintext [u8; 384]? #170

maninkari opened this issue Jun 21, 2022 · 2 comments

Comments

@maninkari
Copy link

Hi,
I've been able to use recrypt for a POC using recrypt.gen_plaintext() but this fails the moment I try to encrypt anything other than that [u8; 384] structure. What if I want to encrypt an image or any other array of bytes that's not 384 bytes length? Is there a work around for this?
Thank you!

@BobWall23
Copy link
Member

The algorithm that is used for proxy re-encryption has very specific requirements for the value that can be encrypted - gen_plaintext() produces those values. To encrypt an arbitrary array of bytes, you can use gen_plaintext(), then pass that to derive_private_key() to generate a key that you can use with AES256-GCM to encrypt the byte array.

Once you have encrypted the bytes, you can encrypt the plaintext to a user or group. When the recipient of the encrypted document and key is ready to decrypt, they decrypt the encrypted plaintext, call the same derive_private_key(), and use AES256-GCM to decrypt the bytes and recover the original data. This process of using a symmetric encryption algorithm for the data and an asymmetric algorithm to protect the key is called "envelope encryption".

These operations are all handled by the ironoxide library, which uses recrypt for the core proxy re-encryption, but does the AES encryption as well.

@maninkari
Copy link
Author

Hi @BobWall23, thank you for replying! I think I understand what you are saying... So is the main purpose of Plaintext to be used to derive a private key with derive_private_key() instead of storing encrypted data of, let's say, a file? That makes sense. Then that derived private key is what I should be using to encrypt and decrypt the file/data. Sweet!
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants