EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Symmetric encryption

Also by EldoS: CallbackRegistry
A component to monitor and control Windows registry access and create virtual registry keys.
#10559
Posted: 07/10/2009 19:15:25
by Ciaran Costelloe (Standard support level)
Joined: 07/10/2009
Posts: 26

Is there any sample code for symmetric encryption of a file/stream (not a PDF file)? I searched the \Samples\ directory for *SymmetricCrypto* with no success.

Ciaran
#10561
Posted: 07/11/2009 03:08:42
by Eugene Mayevski (EldoS Corp.)

The data can be encrypted using symmetric encryption in a number of ways. What particular algorithm / technology are you asking about? Or what are you trying to accomplish?


Sincerely yours
Eugene Mayevski
#10562
Posted: 07/11/2009 03:43:59
by Ciaran Costelloe (Standard support level)
Joined: 07/10/2009
Posts: 26

Hi Eugene.

I want to encrypt and decrypt files using a password (rather than keys). I won't be sending them to anyone else but they may be copied to another computer so I don't want to have to install/copy keys to the other computer.

I thought a class like ElBlowfishSymmetricCrypto might suit this and had hoped that a search in the samples code for "SymmetricCrypto" might find this or one of its relatives, or maybe ElSymmetricCryptoFactory.

But I may be going totally in the wrong direction!

Thanks,
Ciaran
#10563
Posted: 07/11/2009 05:16:59
by Eugene Mayevski (EldoS Corp.)

You have two options : either use OpenPGP technology which does everything for you, or implement your custom encryption scheme based on one of known encryption algorithms. The benefits of OpenPGP are
(a) you have standard passphrase-based key derivation mechanism and you don't need to invent your own. This means stronger security.
(b) if needed you can use other software to encrypt or decrypt the data.

If you want to implement custom scheme, you can search the forum, the questions (and answers) regarding use of Symmetric Crypto classes are asked here from time to time.


Sincerely yours
Eugene Mayevski
#10567
Posted: 07/11/2009 13:24:20
by Ciaran Costelloe (Standard support level)
Joined: 07/10/2009
Posts: 26

Hi Eugene.

Despite the fact that I previously used ElPGPReader for decoding using keys, I did not realise I could use it with a password and no keys. Thank you very much for sorting me out.

Regards,

Ciaran
#10570
Posted: 07/12/2009 18:35:46
by Ciaran Costelloe (Standard support level)
Joined: 07/10/2009
Posts: 26

Hi Eugene.

It all worked fine, thank you very much.

Ciaran

class function TMyPasswordEncoder.Decode(AInPathAndFile, AOutPathAndFile, APassword: string): Boolean;
var
LEncoder: TElPGPReader;
LInputStream, LOutputStream : TMemoryStream;
begin
Result := False;
LEncoder := TElPGPReader.Create(nil);
LInputStream := TMemoryStream.Create();
LOutputStream := TMemoryStream.Create();
try
LEncoder.Passphrase := APassword;
LEncoder.OutputStream := LOutputStream;
LInputStream.LoadFromFile(AInPathAndFile);
LOutputStream.Position := 0;
try
LEncoder.DecryptAndVerify(LInputStream);
except
Exit;
end;
LOutputStream.SaveToFile(AOutPathAndFile);
finally
LInputStream.Destroy;
LOutputStream.Destroy;
LEncoder.Destroy;
end;
Result := True;
end;

class function TMyPasswordEncoder.Encode(AInPathAndFile, AOutPathAndFile, APassword: string;
AMethod: integer {= SB_PGP_ALGORITHM_SK_BLOWFISH}): Boolean;
var
LEncoder: TElPGPWriter;
LInputStream, LOutputStream : TMemoryStream;
begin
Result := False;
LEncoder := TElPGPWriter.Create(nil);
LInputStream := TMemoryStream.Create();
LOutputStream := TMemoryStream.Create();
try
LEncoder.EncryptionType := etPassphrase;
LEncoder.SymmetricKeyAlgorithm := AMethod;
LEncoder.Passphrases.Add(APassword);
LInputStream.LoadFromFile(AInPathAndFile);
LOutputStream.Position := 0;
try
LEncoder.Encrypt(LInputStream, LOutputStream);
except
Exit;
end;
LOutputStream.SaveToFile(AOutPathAndFile);
finally
LInputStream.Destroy;
LOutputStream.Destroy;
LEncoder.Destroy;
end;
Result := True;
end;
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 1536 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!