#include "openssl\pem.h" // should pullin all the others
#pragma comment(lib, "libeay32MT.lib")
// C++ Linker, delay load DLL: libeay32.dll
bool OpenSSLSign(TMemoryStream *in, TMemoryStream *out)
{
bool Result = false;
// LEFT AS AN EXERCISE TO THE READER:
// >>> Load Private Key into "out" stream *HERE* before proceeding any further <<<
BIO *bKey = BIO_new(BIO_s_mem());
BIO_write(bKey, out->Memory, out->Size);
BIO_flush(bKey);
EVP_PKEY *pKey = PEM_read_bio_PrivateKey(bKey, NULL, NULL, NULL);
BIO_free(bKey);
if (pKey) {
EVP_MD_CTX mdctx;
EVP_MD_CTX_init(&mdctx);
EVP_SignInit_ex(&mdctx, EVP_sha1(), NULL);
EVP_SignUpdate(&mdctx, (System::PByte)in->Memory, in->Size);
out->Size = EVP_PKEY_size(pKey);
unsigned int out_len;
Result = EVP_SignFinal(&mdctx, (System::PByte)out->Memory, &out_len, pKey);
SecureZeroMemory(pKey, sizeof(*pKey));
EVP_MD_CTX_cleanup(&mdctx);
}
return Result;
}
//---------------------------------------------------------------------------
#include "openssl\pem.h" // should pullin all the others
#pragma comment(lib, "libeay32MT.lib")
// C++ Linker, delay load DLL: libeay32.dll
bool OpenSSLSign(TMemoryStream *in, TMemoryStream *out)
{
bool Result = false;
// LEFT AS AN EXERCISE TO THE READER:
// >>> Load Private Key into "out" stream *HERE* before proceeding any further <<<
BIO *bKey = BIO_new(BIO_s_mem());
BIO_write(bKey, out->Memory, out->Size);
BIO_flush(bKey);
EVP_PKEY *pKey = PEM_read_bio_PrivateKey(bKey, NULL, NULL, NULL);
BIO_free(bKey);
if (pKey) {
EVP_MD_CTX mdctx;
EVP_MD_CTX_init(&mdctx);
EVP_SignInit_ex(&mdctx, EVP_sha1(), NULL);
EVP_SignUpdate(&mdctx, (System::PByte)in->Memory, in->Size);
out->Size = EVP_PKEY_size(pKey);
unsigned int out_len;
Result = EVP_SignFinal(&mdctx, (System::PByte)out->Memory, &out_len, pKey);
SecureZeroMemory(pKey, sizeof(*pKey));
EVP_MD_CTX_cleanup(&mdctx);
}
return Result;
}
//---------------------------------------------------------------------------
To copy to clipboard, switch view to plain text mode
Bookmarks