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>
14 #include <botan/pem.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());
105 key = decryptor.read_all();
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)
virtual MemoryVector< byte > pkcs8_private_key() const =0
SecureVector< byte > get_contents()
SecureVector< byte > BER_encode(const Private_Key &key)
BER_Decoder & decode(bool &)
BER_Decoder & decode_and_check(const T &expected, const std::string &error_msg)
bool maybe_BER(DataSource &source)
SecureVector< byte > parameters
std::string PEM_encode(const Private_Key &key)
Private_Key * make_private_key(const AlgorithmIdentifier &alg_id, const MemoryRegion< byte > &key_bits, RandomNumberGenerator &rng)
BER_Decoder start_cons(ASN1_Tag, ASN1_Tag=UNIVERSAL)
SecureVector< byte > decode(DataSource &source, std::string &label)
DER_Encoder & encode(bool b)
RandomNumberGenerator * rng
virtual std::string id() const
void encode(const Private_Key &key, Pipe &pipe, X509_Encoding encoding=PEM)
std::string lookup(const OID &oid)
virtual AlgorithmIdentifier pkcs8_algorithm_identifier() const
Private_Key * copy_key(const Private_Key &key, RandomNumberGenerator &rng)
bool matches(DataSource &source, const std::string &extra, size_t search_range)
std::string encode(const byte der[], size_t length, const std::string &label, size_t width)
BER_Decoder & verify_end()
std::string as_string() const
PBE * get_pbe(const std::string &algo_spec)
DER_Encoder & start_cons(ASN1_Tag type_tag, ASN1_Tag class_tag=UNIVERSAL)
Private_Key * load_key(DataSource &source, RandomNumberGenerator &rng, const User_Interface &ui)
virtual std::string get_passphrase(const std::string &, const std::string &, UI_Result &) const
void process_msg(const byte in[], size_t length)