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

What's the best way to handle offline decryption? #126

Open
elliot-sawyer opened this issue Feb 3, 2019 · 3 comments
Open

What's the best way to handle offline decryption? #126

elliot-sawyer opened this issue Feb 3, 2019 · 3 comments
Labels

Comments

@elliot-sawyer
Copy link
Contributor

elliot-sawyer commented Feb 3, 2019

I'm using File::seal to encrypt an uploaded file with a public key. I would like to decrypt it with File::unseal in a separate application using the correct private key, but I'm not able to run a server in the decryption environment. I'd like to create an offline application that replicates what File::unseal does... I attempted to decrypt the cipher with a x25519 Javascript library, but there seems to be more to it than a simple decryption with the private key. Can you outline what steps Halite does, and which ciphers are used, as part of the decryption process?

This library is excellent, thanks so much for creating it!

@paragonie-scott
Copy link
Member

It's using crypto_box_seal_open() internally:

// Get a box keypair (needed by crypto_box_seal_open)
$secret_key = $privateKey->getRawKeyMaterial();
$public_key = \sodium_crypto_box_publickey_from_secretkey($secret_key);
$key_pair = \sodium_crypto_box_keypair_from_secretkey_and_publickey(
$secret_key,
$public_key
);
// Wipe these immediately:
\sodium_memzero($secret_key);
\sodium_memzero($public_key);
// Now let's open that sealed box
$message = \sodium_crypto_box_seal_open(
$ciphertext,
$key_pair
);
// Always memzero after retrieving a value
\sodium_memzero($key_pair);
if (!\is_string($message)) {
// @codeCoverageIgnoreStart
throw new InvalidKey(
'Incorrect secret key for this sealed message'
);
// @codeCoverageIgnoreEnd
}
// We have our encrypted message here
return new HiddenString($message);
}

@larowlan
Copy link
Contributor

File:seal seems to be doing something different to Crypto:seal eg adding the version tag, public key and salt - is libsodium's crypto_box_seal_open able to unseal content sealed with File::seal?

@elliot-sawyer
Copy link
Contributor Author

The JS library I was looking at required some knowledge of the nonce. I don't think Halite exposes it directly, but you might be able to extract it from beginning of the ciphertext

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

No branches or pull requests

3 participants