diff options
author | lloyd <[email protected]> | 2010-06-14 23:58:40 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-06-14 23:58:40 +0000 |
commit | 0d26fdf3e03c7a34c33307352bcc27e79d493eb3 (patch) | |
tree | 27f94d81a8d8bc69d5f50b8cd110f643c79ccdc5 /src/pubkey/pkcs8.cpp | |
parent | 2c17c50fbf663ddc4bcef3c12540c3983b25925f (diff) |
Some PKCS #8 simplifications
Diffstat (limited to 'src/pubkey/pkcs8.cpp')
-rw-r--r-- | src/pubkey/pkcs8.cpp | 24 |
1 files changed, 3 insertions, 21 deletions
diff --git a/src/pubkey/pkcs8.cpp b/src/pubkey/pkcs8.cpp index 35ff7f206..00993223f 100644 --- a/src/pubkey/pkcs8.cpp +++ b/src/pubkey/pkcs8.cpp @@ -133,16 +133,7 @@ SecureVector<byte> PKCS8_decode(DataSource& source, const User_Interface& ui, */ void encode(const Private_Key& key, Pipe& pipe, X509_Encoding encoding) { - const u32bit PKCS8_VERSION = 0; - - SecureVector<byte> contents = - DER_Encoder() - .start_cons(SEQUENCE) - .encode(PKCS8_VERSION) - .encode(key.pkcs8_algorithm_identifier()) - .encode(key.pkcs8_private_key(), OCTET_STRING) - .end_cons() - .get_contents(); + SecureVector<byte> contents = key.PKCS8_BER_encode(); if(encoding == PEM) pipe.write(PEM_Code::encode(contents, "PRIVATE KEY")); @@ -161,11 +152,6 @@ void encrypt_key(const Private_Key& key, { const std::string DEFAULT_PBE = "PBE-PKCS5v20(SHA-1,AES-128/CBC)"; - Pipe raw_key; - raw_key.start_msg(); - encode(key, raw_key, RAW_BER); - raw_key.end_msg(); - std::auto_ptr<PBE> pbe(get_pbe(((pbe_algo != "") ? pbe_algo : DEFAULT_PBE))); pbe->new_params(rng); @@ -174,7 +160,7 @@ void encrypt_key(const Private_Key& key, AlgorithmIdentifier pbe_algid(pbe->get_oid(), pbe->encode_params()); Pipe key_encrytor(pbe.release()); - key_encrytor.process_msg(raw_key); + key_encrytor.process_msg(key.PKCS8_BER_encode()); SecureVector<byte> enc_key = DER_Encoder() @@ -195,11 +181,7 @@ void encrypt_key(const Private_Key& key, */ std::string PEM_encode(const Private_Key& key) { - Pipe pem; - pem.start_msg(); - encode(key, pem, PEM); - pem.end_msg(); - return pem.read_all_as_string(); + return PEM_Code::encode(key.PKCS8_BER_encode(), "PRIVATE KEY"); } /* |