EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Public key confusion

Also by EldoS: BizCrypto
Components for BizTalk® and SQL Server® Integration Services that let you securely store and transfer information in your business automation solutions.
#11891
Posted: 12/09/2009 12:27:57
by Ami Goldi (Basic support level)
Joined: 12/09/2009
Posts: 3

Matthew,

Using RSA, you can encrypt with the private key, which can then only be decrypted with the public key (or private key).

However, the encryption is actually done in reverse, and it's called "Signing" instead of encrypting. Decrypting the signed data with the public key is called "Verifying".

Unfortunately, ElRSAPublicKeyCrypto does not support this functionality. Instead, you can only do "Detached" signing and "Verifying". Lookup ElRSAPublicKeyCrypto.SignDetached and ElRSAPublicKeyCrypto.VerifyDetached for more information..

You can still decrypt (verify) data using the public key in SB, but you'll have to use SBRSA.Decrypt, which is a lower level function.

Here's an example:

Code
  myOutLength = 0;
  SBRSA.Decrypt(@myInputBuffer[1], myInputLength,
    @myElRSAKeyMaterial.PublicModulus[0], Length(myElRSAKeyMaterial.PublicModulus),
    @myElRSAKeyMaterial.PublicExponent[0], Length(myElRSAKeyMaterial.PublicExponent),
    nil, myOutLength);
  SetLength(myOutputBuffer, myOutLength);
  if SBRSA.Decrypt(@myInputBuffer[1], myInputLength,
    @myElRSAKeyMaterial.PublicModulus[0], Length(myElRSAKeyMaterial.PublicModulus),
    @myElRSAKeyMaterial.PublicExponent[0], Length(myElRSAKeyMaterial.PublicExponent),
    @myOutputBuffer[1], myOutLength) then
  begin
    SetLength(myOutputBuffer, myOutLength);
    ShowMessage(myOutputBuffer);
  end;


On the server side, to encrypt (sign) the data using the private key, try PHP's openssl_private_encrypt().

Reply

Statistics

Topic viewed 9156 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!