diff options
author | lloyd <[email protected]> | 2008-06-27 20:21:45 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2008-06-27 20:21:45 +0000 |
commit | 3d0a9fd636e5ca91fcf8f5c0e13dcf659940b564 (patch) | |
tree | 4ce02817eac4c55b27cc75106adce227b4461220 /doc/examples | |
parent | 964dbc067992211e7d566c881de2c7330f46bef2 (diff) |
Update more of the examples
Diffstat (limited to 'doc/examples')
-rw-r--r-- | doc/examples/encrypt.cpp | 4 | ||||
-rw-r--r-- | doc/examples/rsa_dec.cpp | 6 | ||||
-rw-r--r-- | doc/examples/rsa_enc.cpp | 6 |
3 files changed, 11 insertions, 5 deletions
diff --git a/doc/examples/encrypt.cpp b/doc/examples/encrypt.cpp index 5b8ae8684..8d0636c35 100644 --- a/doc/examples/encrypt.cpp +++ b/doc/examples/encrypt.cpp @@ -121,9 +121,11 @@ int main(int argc, char* argv[]) const u32bit key_len = max_keylength_of(algo); const u32bit iv_len = block_size_of(algo); + std::auto_ptr<RandomNumberGenerator> rng(make_rng()); + std::auto_ptr<S2K> s2k(get_s2k("PBKDF2(SHA-1)")); s2k->set_iterations(8192); - s2k->new_random_salt(8); + 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); diff --git a/doc/examples/rsa_dec.cpp b/doc/examples/rsa_dec.cpp index 6f71e2831..910d07adf 100644 --- a/doc/examples/rsa_dec.cpp +++ b/doc/examples/rsa_dec.cpp @@ -32,8 +32,10 @@ int main(int argc, char* argv[]) return 1; } - try { - std::auto_ptr<PKCS8_PrivateKey> key(PKCS8::load_key(argv[1], argv[3])); + try + { + std::auto_ptr<RandomNumberGenerator> rng(make_rng()); + std::auto_ptr<PKCS8_PrivateKey> key(PKCS8::load_key(argv[1], *rng, argv[3])); RSA_PrivateKey* rsakey = dynamic_cast<RSA_PrivateKey*>(key.get()); if(!rsakey) { diff --git a/doc/examples/rsa_enc.cpp b/doc/examples/rsa_enc.cpp index b24074038..e0127d63f 100644 --- a/doc/examples/rsa_enc.cpp +++ b/doc/examples/rsa_enc.cpp @@ -73,6 +73,8 @@ int main(int argc, char* argv[]) return 1; } + std::auto_ptr<RandomNumberGenerator> rng(make_rng()); + std::auto_ptr<PK_Encryptor> encryptor(get_pk_encryptor(*rsakey, "EME1(SHA-1)")); @@ -87,14 +89,14 @@ int main(int argc, char* argv[]) statistically indepedent. Practically speaking I don't think this is a problem. */ - SymmetricKey masterkey(std::min(32U, encryptor->maximum_input_size())); + SymmetricKey masterkey(*rng, std::min(32U, encryptor->maximum_input_size())); SymmetricKey cast_key = derive_key("CAST", masterkey, 16); SymmetricKey mac_key = derive_key("MAC", masterkey, 16); SymmetricKey iv = derive_key("IV", masterkey, 8); SecureVector<byte> encrypted_key = - encryptor->encrypt(masterkey.bits_of()); + encryptor->encrypt(masterkey.bits_of(), *rng); ciphertext << b64_encode(encrypted_key) << std::endl; |