aboutsummaryrefslogtreecommitdiffstats
path: root/doc/examples/encrypt.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'doc/examples/encrypt.cpp')
-rw-r--r--doc/examples/encrypt.cpp21
1 files changed, 15 insertions, 6 deletions
diff --git a/doc/examples/encrypt.cpp b/doc/examples/encrypt.cpp
index f903c2f24..4999fa086 100644
--- a/doc/examples/encrypt.cpp
+++ b/doc/examples/encrypt.cpp
@@ -125,17 +125,26 @@ int main(int argc, char* argv[])
AutoSeeded_RNG rng;
std::auto_ptr<S2K> s2k(get_s2k("PBKDF2(SHA-1)"));
- s2k->set_iterations(8192);
- s2k->new_random_salt(rng, 8);
- SymmetricKey bc_key = s2k->derive_key(key_len, "BLK" + passphrase);
- InitializationVector iv = s2k->derive_key(iv_len, "IVL" + passphrase);
- SymmetricKey mac_key = s2k->derive_key(16, "MAC" + passphrase);
+ SecureVector<byte> salt(8);
+ rng.randomize(&salt[0], salt.size());
+
+ const u32bit PBKDF2_ITERATIONS = 8192;
+
+ SymmetricKey bc_key = s2k->derive_key(key_len, "BLK" + passphrase,
+ &salt[0], salt.size(),
+ PBKDF2_ITERATIONS);
+ InitializationVector iv = s2k->derive_key(iv_len, "IVL" + passphrase,
+ &salt[0], salt.size(),
+ PBKDF2_ITERATIONS);
+ SymmetricKey mac_key = s2k->derive_key(16, "MAC" + passphrase,
+ &salt[0], salt.size(),
+ PBKDF2_ITERATIONS);
// Just to be all fancy we even write a (simple) header.
out << "-------- ENCRYPTED FILE --------" << std::endl;
out << algo << std::endl;
- out << b64_encode(s2k->current_salt()) << std::endl;
+ out << b64_encode(salt) << std::endl;
Pipe pipe(new Fork(
new Chain(new MAC_Filter("HMAC(SHA-1)", mac_key),