file with openssl unit . But after days not successful to do . Any one have example code ?
Do you have a C language working example? We can help you translate it to Pascal...
no . but i write code based on c examples . almost all c example was about to read key in bio format and then get rsa key ... . this is the code but im dont know whats the problem of this code program project1; uses Classes, SysUtils, openssl, base64; function DecryptRSA(const EncryptedData: ansistring; const PrivateKey: ansistring): ansistring; var RSAKey: pRSA; Bio: pBIO; DecryptedLen: integer; DecryptedData: array of byte; begin Bio := BIO_new_mem_buf(@PrivateKey[1], Length(PrivateKey)); RSAKey := PEM_read_bio_PrivateKey(Bio, nil, nil, nil); SetLength(DecryptedData, RSA_size(RSAKey)); DecryptedLen := RSA_private_decrypt(Length(EncryptedData), @EncryptedData[1], @DecryptedData[0], RSAKey, RSA_PKCS1_PADDING); Result := ansistring(Copy(ansistring(DecryptedData), 1, DecryptedLen)); end; var EncryptedString, PrivateKey: ansistring; DecryptedString: ansistring; begin EncryptedString := DecodeStringBase64('...'); PrivateKey := '...'; DecryptedString := DecryptRSA(EncryptedString, PrivateKey); WriteLn('Decrypted Data: ', DecryptedString); end.
this was c example https://hayageek.com/rsa-encryption-decryption-openssl-c/
Will take a look and try to help you
What error are you getting?
Did you know this example: https://github.com/fpc/FPCSource/blob/main/packages/openssl/examples/genkeypair.lpr
thank you 🙏 actually i write code that worked and only problem is code working by not the way should be . take look at this topic i created https://forum.lazarus.freepascal.org/index.php?topic=66394.0 the problem is the way that get rsa from EVP_PKEY
this example is generate rsa key and assigned to EVP_PKEY we need to do reverse : load key to EVP_PKEY and get its rsa
Обсуждают сегодня