EldoS | Feel safer!

Software components for data protection, secure storage and transfer

3Des Encryption/Decryption

Also by EldoS: CallbackProcess
A component to control process creation and termination in Windows and .NET applications.
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...

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

  //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);
     Crypto.Encrypt(InF, OutF);

I'd appreciate the help, thanks!
Posted: 03/16/2011 00:25:15
by Eugene Mayevski (Team)

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
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!

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
Posted: 01/08/2016 11:12:33
by Eugene Mayevski (Team)

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: Callback File System
Create virtual file systems and disks, expose and manage remote data as if they were files on the local disk.



Topic viewed 3079 times

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


Back to top

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

Got it!