2
\$\begingroup\$

I'm using TurboPower LockBox for the first time, and using the TwoFish algorithm to first encrypt a password, and later retrieve the password by decrypting the generated hash.

I would like to know if the approach that I'm using is good, and if there are any pitfalls to avoid. Its a simple use case for my application to store and later retrieve a mail server password.

This is the code I'm using:

// Steve Faleiro 2016-03-06
uses uTPLb_CryptographicLibrary, uTPLb_Codec;

function TwoFish_ENC(const AString: String): String;
var
  CryptoLib: TCryptographicLibrary;
  Codec: TCodec;
  encryptedStr: String;
begin
  CryptoLib := TCryptographicLibrary.Create(nil);
  Codec := TCodec.Create(nil);
  try
    Codec.CryptoLibrary := CryptoLib;
    Codec.StreamCipherId := 'native.StreamToBlock';
    Codec.BlockCipherId := 'native.Twofish';
    Codec.ChainModeId := 'native.CBC';

    Codec.Reset;
    Codec.Password := '56410AD2-9DD6-4B8C-9D2F-5DE7A7F7085E';
    Codec.EncryptString(AString, encryptedStr, TEncoding.UTF8);
  finally
    CryptoLib.Free;
    Codec.Free;
  end;

  Result := encryptedStr;
end;

function TwoFish_DEC(const AString: String): String;
var
  CryptoLib: TCryptographicLibrary;
  Codec: TCodec;
  decryptedStr: String;
begin
  CryptoLib := TCryptographicLibrary.Create(nil);
  Codec := TCodec.Create(nil);
  try
    Codec.CryptoLibrary := CryptoLib;
    Codec.StreamCipherId := 'native.StreamToBlock';
    Codec.BlockCipherId := 'native.Twofish';
    Codec.ChainModeId := 'native.CBC';

    Codec.Reset;
    Codec.Password := '56410AD2-9DD6-4B8C-9D2F-5DE7A7F7085E';
    Codec.DecryptString(decryptedStr, AString, TEncoding.UTF8);
  finally
    CryptoLib.Free;
    Codec.Free;
  end;

  Result := decryptedStr;
end;

Is it good enough? If not, is there any way to improve it?

\$\endgroup\$
3
  • \$\begingroup\$ Is it good enough? What's your threat model? \$\endgroup\$
    – Mast
    Commented Mar 7, 2016 at 7:46
  • \$\begingroup\$ Ordinary home-based business. Nothing much. \$\endgroup\$
    – Steve F
    Commented Mar 8, 2016 at 16:28
  • 1
    \$\begingroup\$ I would use the newer versions of LockBox. There are at least two people I know of who are working on this. The TurboPower one is quite old. \$\endgroup\$ Commented Sep 27, 2016 at 13:48

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.