Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9046899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T11:46:09+00:00 2026-06-16T11:46:09+00:00

I am experimenting with OpenSSL for Delphi a unit that you can find here

  • 0

I am experimenting with OpenSSL for Delphi a unit that you can find here . So far I am able to generate a public / private key. What I am trying to do is sign a string and then check if the string is signed with the public key.

So.. here is what I have so far. The problem is that EVP_SignFinal causes an access violation because EVP_PKEY_assign always returns pKey = nil so I guess the key is not assigned from the memory how can I assign It.

PS . You have to excuse the code is just a test 😉

Could somebody point me where I am wrong ?

var
  rsa : pRSA;
  eu : string;
  privateKey,publicKey,Err : pBIO;
  enc : pEVP_CIPHER;
  keylen : Cardinal;
  prv,pub : PChar;
  hash : TMD5Digest;
  mdctx : EVP_MD_CTX;
  pkey : pEVP_PKEY;
  lbuf : array [0..15] of Byte;
  i : Integer;
begin
  ERR_load_crypto_strings;
  OpenSSL_add_all_algorithms;
  OpenSSL_add_all_ciphers;
  OpenSSL_add_all_digests;
  eu := 'SIGN THIS';
  enc := EVP_des_ede3_cbc;


  rsa := RSA_generate_key(1024,RSA_F4,nil,Err);
  if rsa <> nil then
  begin
  privateKey := BIO_new(BIO_s_mem);
  PEM_write_bio_RSAPrivateKey(privateKey,rsa,enc,nil,0,nil,PChar('0PC0DE'));
  publicKey := BIO_new(BIO_s_mem);
  PEM_write_bio_RSAPublicKey(publicKey,rsa);
  keylen := BIO_pending(privateKey);
  GetMem(prv,keylen + 1);
  BIO_read(privateKey,prv,keylen);
  keylen := BIO_pending(publicKey);
  GetMem(pub,keylen + 1);
  BIO_read(publicKey,pub,keylen);
  Writeln(prv);
  Writeln('Keys generated!');
  pKey := nil;
  EVP_PKEY_assign(pkey,EVP_PKEY_RSA,pub);
  EVP_MD_CTX_init(@mdctx);
  EVP_SignInit(@mdctx,EVP_md5());
  EVP_SignUpdate(@mdctx,PChar(eu),Length(eu));
  EVP_SignFinal(@mdctx,@lbuf,keylen,pkey);
  EVP_MD_CTX_cleanup(@mdctx);
  WriteLn(keylen);

  Readln;
  end;
end;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T11:46:10+00:00Added an answer on June 16, 2026 at 11:46 am

    I think the mistake is that you are trying to sign with the public key instead of the private key. You always use the public key for encryption (and the private for decryption) and the private key for signing (and thus the public key for verification).

    Furthermore, it seems to me that it is better to use PEM_read_bio_RSAPrivateKey instead of EVP_PKEY_assign, as it seems to be the direct opposite of PEM_write_bio_RSAPrivateKey. EVP_PKEY_assign seems to be a deprecated call, and is unlikely to handle PEM encoding.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I experimenting with jQuery. As I was trying I found out that I can't
Im experimenting with the espn public API and am trying to use their json
Experimenting with jQuery and trying to make a small slide show that rotates through
I need to use a Delphi component to encrypt a file that can then
While experimenting with C++11 new features, I discovered that the std::placeholders::_1 can't be directly
Experimenting with Scala... I'm trying to define something analogous to the @ hack in
When experimenting with (embedded) Apache Derby DB, I noticed that a fresh database, with
I'm experimenting with Spring Mobile but I can't seem to get the basic example
Experimenting with Spring-JDBC. I am using this as reference. I am trying to get
From experimenting with the r.js optimizer, it seems that there is no way for

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.