8#include <botan/pkcs8.h>
9#include <botan/get_pbe.h>
10#include <botan/der_enc.h>
11#include <botan/ber_dec.h>
12#include <botan/asn1_obj.h>
13#include <botan/oids.h>
15#include <botan/internal/pk_algs.h>
49 bool is_encrypted =
true;
53 key_data = PKCS8_extract(source, pbe_alg_id);
58 if(label ==
"PRIVATE KEY")
60 else if(label ==
"ENCRYPTED PRIVATE KEY")
63 key_data = PKCS8_extract(key_source, pbe_alg_id);
80 const size_t MAX_TRIES = 3;
86 if(MAX_TRIES && tries >= MAX_TRIES)
92 std::auto_ptr<PBE> pbe(
get_pbe(pbe_alg_id.
oid, params));
95 const std::string passphrase =
101 pbe->set_key(passphrase);
102 Pipe decryptor(pbe.release());
110 .decode_and_check<
size_t>(0,
"Unknown PKCS #8 version number")
136 const size_t PKCS8_VERSION = 0;
160 const std::string& pass,
161 const std::string& pbe_algo)
163 const std::string DEFAULT_PBE =
"PBE-PKCS5v20(SHA-1,AES-256/CBC)";
165 std::auto_ptr<PBE> pbe(
get_pbe(((pbe_algo !=
"") ? pbe_algo : DEFAULT_PBE)));
167 pbe->new_params(rng);
172 Pipe key_encrytor(pbe.release());
188 const std::string& pass,
189 const std::string& pbe_algo)
195 "ENCRYPTED PRIVATE KEY");
209 if(alg_name ==
"" || alg_name == alg_id.
oid.
as_string())
232 const std::string& pass)
242 const std::string& pass)
SecureVector< byte > parameters
BER_Decoder(DataSource &)
DER_Encoder & start_cons(ASN1_Tag type_tag, ASN1_Tag class_tag=UNIVERSAL)
SecureVector< byte > get_contents()
DER_Encoder & encode(bool b)
virtual std::string id() const
std::string as_string() const
SecureVector< byte > read_all(message_id msg=DEFAULT_MESSAGE)
void process_msg(const byte in[], size_t length)
virtual MemoryVector< byte > pkcs8_private_key() const =0
virtual AlgorithmIdentifier pkcs8_algorithm_identifier() const
virtual std::string get_passphrase(const std::string &, const std::string &, UI_Result &) const
User_Interface(const std::string &="")
bool maybe_BER(DataSource &source)
std::string lookup(const OID &oid)
std::string encode(const byte der[], size_t length, const std::string &label, size_t width)
bool matches(DataSource &source, const std::string &extra, size_t search_range)
SecureVector< byte > decode(DataSource &source, std::string &label)
SecureVector< byte > BER_encode(const Private_Key &key)
Private_Key * copy_key(const Private_Key &key, RandomNumberGenerator &rng)
Private_Key * load_key(DataSource &source, RandomNumberGenerator &rng, const User_Interface &ui)
std::string PEM_encode(const Private_Key &key)
Private_Key * make_private_key(const AlgorithmIdentifier &alg_id, const MemoryRegion< byte > &key_bits, RandomNumberGenerator &rng)
PBE * get_pbe(const std::string &algo_spec)
Decoding_Error(const std::string &name)
PKCS8_Exception(const std::string &error)