EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Using ElBlowfishSymmetricCrypto

Also by EldoS: MsgConnect
Cross-platform protocol-independent communication framework for building peer-to-peer and client-server applications and middleware components.
#503
Posted: 06/21/2006 08:31:09
by Luis Arenal (Standard support level)
Joined: 05/10/2006
Posts: 9

Can you orient me on how to configure an instance of type ElBlowfishSymmetricCrypto in Delphi to Encrypt a stream? i'm having trouble specially on assigning the KeyMaterial, but if you could give me an example of the whole procedure, I'd appreciate it.
Thank you.
Regards, Luis.
#509
Posted: 06/21/2006 13:49:05
by Ken Ivanov (EldoS Corp.)

Please use the following code as a guide:
Code
procedure SampleBlowfishEncryption;
var
  Crypto : TElBlowfishSymmetricCrypto;
  Key : TElSymmetricKeyMaterial;
  InF, OutF : TFileStream;
  IV : ByteArray;
begin
  Crypto := TElBlowfishSymmetricCrypto.Create(cmCBC);
  try
    Key := TElSymmetricKeyMaterial.Create();
    try
      Key.Generate(128);
      SetLength(IV, 8);
      SBRndGenerate(@IV[0], Length(IV));
      Key.IV := IV;
      Crypto.KeyMaterial := Key;
      InF := TFileStream.Create('infile', fmOpenRead);
      try
        OutF := TFileStream.Create('outfile', fmCreate);
        try
          Crypto.Encrypt(InF, OutF);
        finally
          FreeAndNil(OutF);
        end;
      finally
        FreeAndNil(InF);
      end;
    finally
      FreeAndNil(Key);
    end;
  finally
    FreeAndNil(Crypto);
  end;
end;
#523
Posted: 06/22/2006 14:16:18
by Luis Arenal (Standard support level)
Joined: 05/10/2006
Posts: 9

Ok, I tried the following code to encrypt a string but I get an 'Invalid padding' exception on the call to Encrypt:

procedure SampleBlowfishEncryption;
var
Crypto : TElBlowfishSymmetricCrypto;
Key : TElSymmetricKeyMaterial;
InS, OutS : TStringStream;
IV : ByteArray;
begin
Crypto := TElBlowfishSymmetricCrypto.Create(cmCBC);
try
Key := TElSymmetricKeyMaterial.Create();
try
Key.Generate(128);
SetLength(IV, 8);
SBRndGenerate(@IV[0], Length(IV));
Key.IV := IV;
Crypto.KeyMaterial := Key;
InS := TStringStream.Create('a test string');
try
OutS := TStringStream.Create('');
try
Crypto.Encrypt(InS, OutS);
finally
FreeAndNil(OutS);
end;
finally
FreeAndNil(InS);
end;
finally
FreeAndNil(Key);
end;
finally
FreeAndNil(Crypto);
end;
end;

What's the padding for in this case?
Thank you.
#527
Posted: 06/23/2006 02:35:23
by Ken Ivanov (EldoS Corp.)

By default all descendants of TElSymmetricCrypto use 'none' padding type. This padding type can be used to encrypt only amounts of data divisible by the cipher block size. I.e., in the case of Blowfish cipher you can encrypt chunks of 8, 16, 24, 32, ... bytes long (as Blowfish's block size is 8).

If you need to encrypt data of arbitrary length, please consider using PKCS#5 padding:

Crypto.Padding := cpPKCS5;
#15882
Posted: 02/24/2011 00:46:40
by DWS DWS (Priority Standard support level)
Joined: 02/24/2011
Posts: 17

Hi,

I am currently evaluating SecureBlackbox for my company. I saw the code above for Blowfish encryption and tried to test the code. I got stuck with SBRndGenerate and couldn't figure out which unit it was coming from.

Any help is greatly appreciated.

Regards,
Margaux
#15883
Posted: 02/24/2011 01:18:48
by Eugene Mayevski (EldoS Corp.)

You need to reference SBUtils (which you do anyway as you need to call SetLicenseKey method to set the license key (even the evaluation one).


Sincerely yours
Eugene Mayevski
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.

Reply

Statistics

Topic viewed 3722 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!