MCPcopy Create free account
hub / github.com/3rdparty/libprocess / sign_rsa_sha256

Function sign_rsa_sha256

src/ssl/utilities.cpp:410–441  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

408
409
410Try<string> sign_rsa_sha256(
411 const string& message,
412 shared_ptr<RSA> private_key)
413{
414 vector<unsigned char> signatureData;
415 signatureData.reserve(RSA_size(private_key.get()));
416 unsigned int signatureLength;
417 unsigned char hash[SHA256_DIGEST_LENGTH];
418
419 SHA256(
420 reinterpret_cast<const unsigned char*>(message.c_str()),
421 message.size(),
422 hash);
423
424 int success = RSA_sign(
425 NID_sha256,
426 hash,
427 SHA256_DIGEST_LENGTH,
428 signatureData.data(),
429 &signatureLength,
430 private_key.get());
431
432 if (success == 0) {
433 const char* reason = ERR_reason_error_string(ERR_get_error());
434 return Error("Failed to sign the message" +
435 (reason == nullptr ? "" : ": " + string(reason)));
436 }
437
438 return string(
439 reinterpret_cast<char*>(signatureData.data()),
440 signatureLength);
441}
442
443
444Try<Nothing> verify_rsa_sha256(

Callers 2

createMethod · 0.85
TESTFunction · 0.85

Calls 2

getMethod · 0.45
sizeMethod · 0.45

Tested by 1

TESTFunction · 0.68