diff options
Diffstat (limited to 'crypto/signature_creator_openssl.cc')
-rw-r--r-- | crypto/signature_creator_openssl.cc | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/crypto/signature_creator_openssl.cc b/crypto/signature_creator_openssl.cc index fa9ba07..e46d3d0 100644 --- a/crypto/signature_creator_openssl.cc +++ b/crypto/signature_creator_openssl.cc @@ -5,6 +5,7 @@ #include "crypto/signature_creator.h" #include <openssl/evp.h> +#include <openssl/rsa.h> #include "base/logging.h" #include "base/memory/scoped_ptr.h" @@ -24,6 +25,27 @@ SignatureCreator* SignatureCreator::Create(RSAPrivateKey* key) { return result.release(); } +// static +bool SignatureCreator::Sign(RSAPrivateKey* key, + const uint8* data, + int data_len, + std::vector<uint8>* signature) { + RSA* rsa_key = EVP_PKEY_get1_RSA(key->key()); + if (!rsa_key) + return false; + signature->resize(RSA_size(rsa_key)); + + unsigned int len = 0; + bool success = RSA_sign(NID_sha1, data, data_len, vector_as_array(signature), + &len, rsa_key); + if (!success) { + signature->clear(); + return false; + } + signature->resize(len); + return true; +} + SignatureCreator::SignatureCreator() : sign_context_(EVP_MD_CTX_create()) { } |