EldoS | Feel safer!

Software components for data protection, secure storage and transfer

3Des Encryption/Decryption

Also by EldoS: RawDisk
Access locked and protected files in Windows, read and write disks and partitions and more.
#16064
Posted: 03/15/2011 20:35:45
by DWS DWS (Priority Standard support level)
Joined: 02/24/2011
Posts: 17

Hi All,

I need help with using SecureBlackBox in performing 3DES Encryption/Decryption(VCL). I've searched the forums, the help and the samples but couldn't find any. Anyone can provide some examples?

Here's the code I've been using. For the key buffer size, I've tried 168 bits and 192 bits. I've read that 3DES keys are 192 bits, where 3x64 bits key (each key is 56 bits + 8 parity bits). With the code below, I get an "invalid key material" error. I'm probably missing something...

Code
var
  Crypto : TEl3DESSymmetricCrypto;
  Key : TElSymmetricKeyMaterial;
  InF, OutF, KeyF : TFileStream;
  testkey : ByteArray;
  keystring : string;
begin
  //Convert some random strings into a 192 bit array.
  keystring := '4d89g13j4j91j27c582ji123';
  SetLength(testkey, 24);
  for i  := 0 to length(keystring) - 1 do
  begin
    testkey[i] := Ord(keystring[i]);
  end;

  //Instantiate the Key object
  Key := TElSymmetricKeyMaterial.Create();
  Key.Algorithm := SB_PGP_ALGORITHM_SK_3DES;
  Key.Key := testkey;

  Crypto := TEl3DESSymmetricCrypto.Create(cmCBC);
  Crypto.KeyMaterial := Key;
  InF := TFileStream.Create('C:\Projects\testencrypt\test.txt', fmOpenRead);
  OutF := TFileStream.Create('C:\Projects\testencrypt\encrypted.txt', fmCreate);
  try
     Crypto.Encrypt(InF, OutF);
  finally
     FreeAndNil(OutF);
  end;
end;  


I'd appreciate the help, thanks!
#16065
Posted: 03/16/2011 00:25:15
by Eugene Mayevski (EldoS Corp.)

1) You need to use another algorithm constant, namely SB_ALGORITHM_CNT_3DES
2) In CBC encryption mode you must set IV in KeyMaterial.


Sincerely yours
Eugene Mayevski
#16066
Posted: 03/16/2011 00:48:35
by DWS DWS (Priority Standard support level)
Joined: 02/24/2011
Posts: 17

Hi Eugene,

That works, thanks!

--Margaux
#35465
Posted: 01/08/2016 11:06:33
by Rafael Cuadrado (Standard support level)
Joined: 01/08/2016
Posts: 1

Hi Mrs,
there is any example to decrypt file in C# .NET, additional, do I need to buy OpenPGP package to decrypt 3des files?

I'll buy it anyway to encrypt a file with PGP but I want to know if I need OpenPGP to decrypt a 3des Encrypted file.

Thank you.

-- Kind Regards
#35466
Posted: 01/08/2016 11:12:33
by Eugene Mayevski (EldoS Corp.)

Please don't post to unrelated topics. Thank you.

It's not clear from your question what you are trying to do. "3des files" is not a file format. 3DES is a symmetric encryption algorithm. Most file encryption format support this algorithm. However it's not clear from your question, what format you need to handle. PGP files are handled with OpenPGPBlackbox package. As for other file formats - it depends on the format.


Sincerely yours
Eugene Mayevski
Also by EldoS: Rethync
The cross-platform framework that simplifies synchronizing data between mobile and desktop applications and servers and cloud storages

Reply

Statistics

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