diff options
Diffstat (limited to 'src/pubkey/pkcs8.h')
-rw-r--r-- | src/pubkey/pkcs8.h | 89 |
1 files changed, 64 insertions, 25 deletions
diff --git a/src/pubkey/pkcs8.h b/src/pubkey/pkcs8.h index 920f8c24a..24f28086b 100644 --- a/src/pubkey/pkcs8.h +++ b/src/pubkey/pkcs8.h @@ -25,31 +25,11 @@ struct BOTAN_DLL PKCS8_Exception : public Decoding_Error namespace PKCS8 { /** -* Encode a private key into a pipe. +* BER encode a private key * @param key the private key to encode -* @param pipe the pipe to feed the encoded key into -* @param enc the encoding type to use +* @return BER encoded key */ -BOTAN_DLL void encode(const Private_Key& key, Pipe& pipe, - X509_Encoding enc = PEM); - -/** -* Encode and encrypt a private key into a pipe. -* @param key the private key to encode -* @param pipe the pipe to feed the encoded key into -* @param pass the password to use for encryption -* @param rng the rng to use -* @param pbe_algo the name of the desired password-based encryption algorithm; - if empty ("") a reasonable (portable/secure) default will be chosen. -* @param enc the encoding type to use -*/ -BOTAN_DLL void encrypt_key(const Private_Key& key, - Pipe& pipe, - RandomNumberGenerator& rng, - const std::string& pass, - const std::string& pbe_algo = "", - X509_Encoding enc = PEM); - +BOTAN_DLL SecureVector<byte> BER_encode(const Private_Key& key); /** * Get a string containing a PEM encoded private key. @@ -59,19 +39,78 @@ BOTAN_DLL void encrypt_key(const Private_Key& key, BOTAN_DLL std::string PEM_encode(const Private_Key& key); /** +* Encrypt a key using PKCS #8 encryption +* @param key the key to encode +* @param rng the rng to use +* @param pass the password to use for encryption +* @param pbe_algo the name of the desired password-based encryption + algorithm; if empty ("") a reasonable (portable/secure) + default will be chosen. +* @return the encrypted key in binary BER form +*/ +BOTAN_DLL SecureVector<byte> BER_encode(const Private_Key& key, + RandomNumberGenerator& rng, + const std::string& pass, + const std::string& pbe_algo = ""); + +/** * Get a string containing a PEM encoded private key, encrypting it with a * password. * @param key the key to encode * @param rng the rng to use * @param pass the password to use for encryption -* @param pbe_algo the name of the desired password-based encryption algorithm; - if empty ("") a reasonable (portable/secure) default will be chosen. +* @param pbe_algo the name of the desired password-based encryption + algorithm; if empty ("") a reasonable (portable/secure) + default will be chosen. +* @return the encrypted key in PEM form */ BOTAN_DLL std::string PEM_encode(const Private_Key& key, RandomNumberGenerator& rng, const std::string& pass, const std::string& pbe_algo = ""); + +/** +* Encode a private key into a pipe. This function is deprecated. +* @param key the private key to encode +* @param pipe the pipe to feed the encoded key into +* @param encoding the encoding type to use +*/ +inline void encode(const Private_Key& key, + Pipe& pipe, + X509_Encoding encoding = PEM) + { + if(encoding == PEM) + pipe.write(PKCS8::PEM_encode(key)); + else + pipe.write(PKCS8::BER_encode(key)); + } + +/** +* Encode and encrypt a private key into a pipe. This function is +* deprecated. +* @param key the private key to encode +* @param pipe the pipe to feed the encoded key into +* @param pass the password to use for encryption +* @param rng the rng to use +* @param pbe_algo the name of the desired password-based encryption + algorithm; if empty ("") a reasonable (portable/secure) + default will be chosen. +* @param encoding the encoding type to use +*/ +inline void encrypt_key(const Private_Key& key, + Pipe& pipe, + RandomNumberGenerator& rng, + const std::string& pass, + const std::string& pbe_algo = "", + X509_Encoding encoding = PEM) + { + if(encoding == PEM) + pipe.write(PKCS8::PEM_encode(key, rng, pass, pbe_algo)); + else + pipe.write(PKCS8::BER_encode(key, rng, pass, pbe_algo)); + } + /** * Load a key from a data source. * @param source the data source providing the encoded key |