Secure key encryption solution in Delphi & PHP?

My application sends encrypted files over the Internet, I need to be able to do the following:

  • ( Client side Delphi 2010) . Encrypt files using the public key that comes with my application and upload it to the server
  • ( Server version of PHP) . Decrypt the downloaded file using a private private key stored on the server
  • (Working with the downloaded file ...)

It sounds simple, but I cannot find a reliable code / component, I found these components:

  • DCPcrypt . This is what I use now in development, but does not seem to support keypair-based encryption (RSA?)

  • GnuPgp (GPL), so I can’t use it in my commercial application.

  • TurboPower LockBox 3 : supports keypair encryption, but very cryptic (without AFAIK documentation) and doesn't seem to support file encryption.

My question is: is there a secure / reliable encryption component that:

  • Achieve what I described above (e.g. encryption with keypair).
  • Can be decrypted using PHP
  • Works with large files / streams
  • ( Dream here! ). A simple delphi / php demo that shows how to do this? :)
  • FOSS solutions only, please, I already worked on the budget :)
+5
source share
2 answers

OpenSSL.
PHP, , , : .

Delphi OpenSSL , , : http://www.disi.unige.it/person/FerranteM/delphiopenssl/. . Indy OpenSSL.

, , , , : -)

EDIT:

Delphi EVP_Seal *, libeay32.pas SO-. , Indy / EVP_, .

PHP .

, EVP_Seal * ( ):

function EVPSeal(ASource: TBytes; const APublicKey: PEVP_PKEY; out Key: TBytes; out IV: TBytes): TBytes; 
var
  cipher: PEVP_CIPHER;
  ctx: EVP_CIPHER_CTX;
  buf: TBytes;
  block_size, buf_start, out_len, keysize: integer;
  ek: array[0..0] of PByte;
  ekl: array[0..0] of integer;
  pubk: array[0..0] of PEVP_PKEY;
begin
  keysize := EVP_PKEY_size(APublicKey);
  cipher := EVP_aes_256_cbc;
  SetLength(IV, EVP_MAX_IV_LENGTH);
  SetLength(Key, keysize);
  ek[0] := @Key[0];
  pubk[0] := APublicKey;
  buf_start := 0;
  EVP_CIPHER_CTX_init(@ctx);
  try
    EVP_SealInit(@ctx, cipher, @ek[0], @ekl, @IV[0], @pubk[0], 1);
    block_size := EVP_CIPHER_CTX_block_size(@ctx);
    SetLength(buf, Length(ASource) + block_size);
    SetLength(Key, ekl[0]);
    EVP_SealUpdate(@ctx, @buf[buf_start], out_len, @ASource[0], Length(ASource));
    Inc(buf_start, out_len);
    EVP_SealFinal(@ctx, @buf[buf_start], out_len);
    Inc(buf_start, out_len);
    SetLength(buf, buf_start);
    result := buf;
  finally
    EVP_CIPHER_CTX_cleanup(@ctx);
  end;
end;
+3

, . , , , , .

, XML- . , - . , .

( : flamewar , . , , . .)

+2

All Articles