diff options
Diffstat (limited to 'src/lib/pubkey/pk_keys.cpp')
-rw-r--r-- | src/lib/pubkey/pk_keys.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/lib/pubkey/pk_keys.cpp b/src/lib/pubkey/pk_keys.cpp index ebaa0eb69..9597ed08d 100644 --- a/src/lib/pubkey/pk_keys.cpp +++ b/src/lib/pubkey/pk_keys.cpp @@ -8,6 +8,8 @@ #include <botan/pk_keys.h> #include <botan/der_enc.h> #include <botan/oids.h> +#include <botan/hash.h> +#include <botan/hex.h> namespace Botan { @@ -52,4 +54,28 @@ void Private_Key::gen_check(RandomNumberGenerator& rng) const throw Self_Test_Failure("Private key generation failed"); } +/* +* Hash of the PKCS #8 encoding for this key object +*/ +std::string Private_Key::fingerprint(const std::string& alg) const + { + secure_vector<byte> buf = pkcs8_private_key(); + std::unique_ptr<HashFunction> hash(HashFunction::create(alg)); + hash->update(buf); + const auto hex_print = hex_encode(hash->final()); + + std::string formatted_print; + + for(size_t i = 0; i != hex_print.size(); i += 2) + { + formatted_print.push_back(hex_print[i]); + formatted_print.push_back(hex_print[i+1]); + + if(i != hex_print.size() - 2) + formatted_print.push_back(':'); + } + + return formatted_print; + } + } |