Recent

Author Topic: How to use dcpcrypt??  (Read 32100 times)

jshand2010

  • Full Member
  • ***
  • Posts: 234
How to use dcpcrypt??
« on: October 31, 2010, 06:32:39 pm »
i keep reading about how to use this module(s), but have never really understood how to code it into my software.

please can someone give me step by step instructions

many thanks for your help
OpenSUSE Tumbleweed x86_64, Lazarus 2.2.0RC2 fixes branch, fpc 3.2.3 fixes branch

faber

  • Guest
Re: How to use dcpcrypt??
« Reply #1 on: October 31, 2010, 06:42:12 pm »
Demos and help on dcpcrypt home page: http://www.cityinthesky.co.uk/cryptography.html

sfeinst

  • Full Member
  • ***
  • Posts: 186
Re: How to use dcpcrypt??
« Reply #2 on: October 31, 2010, 06:49:50 pm »
I don't use the LCL for it, but here is how I code using the library:

I add the following to uses:
DCPrijndael, DCPSha256

Then when loading data from a file (leaving out what I do with the data:
var
   Crypt: TDCP_rijndael;
   FileData: TFileStream;
        Data: TStringStream;
begin
  FileData := TFileStream.Create(Filename, fmOpenRead);
  Crypt := TDCP_rijndael.Create(nil);
  try
    Crypt.InitStr(Self.Password, TDCP_sha256);   // self-Password is the password used to save the file
    Crypt.DecryptStream(FileData, Data, FileData.Size);
    Crypt.Burn;
    // I then use Data as if it was not encrypted
   ...
  finally
    FreeAndNil(Crypt);
    FreeAndNil(Data);
    FreeAndNil(FileData);
  end;


to save a file I do the following:

var
   Crypt: TDCP_rijndael;
   FileData: TFileStream;
   Data: TStringStream;
begin
  FileData := TFileStream.Create(Filename, fmCreate);
  Data := TStringStream.Create('');
  Crypt := TDCP_rijndael.Create(nil);
  try
    // I write data out to a stream
  ...
    // then using that stream, I encrypt it to a file
    Crypt.InitStr(Self.Password, TDCP_sha256);
    Crypt.EncryptStream(Data, FileData, Data.Size);
    Crypt.Burn;
  finally
    FreeAndNil(Crypt);
    FreeAndNil(Data);
    FreeAndNil(FileData);
  end;

jshand2010

  • Full Member
  • ***
  • Posts: 234
Re: How to use dcpcrypt??
« Reply #3 on: November 15, 2010, 03:33:35 am »
I have tried using this code and it doesn't work.  i may have just missed the point that need attention.  please give me step by step instructions on how to set this up
OpenSUSE Tumbleweed x86_64, Lazarus 2.2.0RC2 fixes branch, fpc 3.2.3 fixes branch

sfeinst

  • Full Member
  • ***
  • Posts: 186
Re: How to use dcpcrypt??
« Reply #4 on: November 16, 2010, 11:46:43 am »
My steps would be very similar to the code I posted.  It might be easier instead if you post the code you are trying and the error you are getting.

Dibo

  • Hero Member
  • *****
  • Posts: 1048
Re: How to use dcpcrypt??
« Reply #5 on: November 16, 2010, 12:13:07 pm »
This is my code how I encrypt string:
Code: Pascal  [Select][+][-]
  1. uses DCPrijndael, DCPsha256;
  2.  
  3. var
  4.   S1, S2: String;
  5.   c: TDCP_rijndael;
  6. begin
  7.   c := TDCP_rijndael.Create(nil);
  8.   try
  9.     c.InitStr('MyCustomKey', TDCP_sha256);
  10.     S1 := c.EncryptString('First string');
  11.     c.Reset;
  12.     S2 := c.EncryptString('Second string');
  13.   finally
  14.     c.Free;
  15.   end;
  16. end;  
  17.  
And decrypt:
Code: Pascal  [Select][+][-]
  1. uses DCPrijndael, DCPsha256;
  2.  
  3. var
  4.   S1, S2: String;
  5.   c: TDCP_rijndael;
  6. begin
  7.   c := TDCP_rijndael.Create(nil);
  8.   try
  9.     c.InitStr('MyCustomKey', TDCP_sha256);
  10.     S1 := c.DecryptString(SomeEncryptedVariable);
  11.     c.Reset;
  12.     S2 := c.DecryptString(SomeEncryptedVariable);
  13.   finally
  14.     c.Free;
  15.   end;
  16. end;  
  17.  
One thing I noticed. If you want to encrypt / decrypt next string using the same object, you must first reset this object by "Reset" call. Otherwise, next string will be incorrectly encrypted / decrypted

sfeinst

  • Full Member
  • ***
  • Posts: 186
Re: How to use dcpcrypt??
« Reply #6 on: November 16, 2010, 12:37:09 pm »
Are you saying the code you posted fails or does work?  If it fails, what is wrong.  If it works, what is your question?

Dibo

  • Hero Member
  • *****
  • Posts: 1048
Re: How to use dcpcrypt??
« Reply #7 on: November 16, 2010, 03:16:51 pm »
It works. This is only another example how to use dcrypt (jshand2010 question in first post)

sfeinst

  • Full Member
  • ***
  • Posts: 186
Re: How to use dcpcrypt??
« Reply #8 on: November 16, 2010, 03:31:57 pm »
It works. This is only another example how to use dcrypt (jshand2010 question in first post)
Sorry, I mistook your post for the original poster's.

jshand2010

  • Full Member
  • ***
  • Posts: 234
Re: How to use dcpcrypt??
« Reply #9 on: November 26, 2010, 11:20:03 pm »
you know when you spoke about adding clauses DCPr.... to the uses part??

you mentioned that i also need to go to project options etc....  at this stage.  i am unsure to where to put the paths to those clauses.

please help
OpenSUSE Tumbleweed x86_64, Lazarus 2.2.0RC2 fixes branch, fpc 3.2.3 fixes branch

sfeinst

  • Full Member
  • ***
  • Posts: 186
Re: How to use dcpcrypt??
« Reply #10 on: November 28, 2010, 03:38:32 am »
you know when you spoke about adding clauses DCPr.... to the uses part??

you mentioned that i also need to go to project options etc....  at this stage.  i am unsure to where to put the paths to those clauses.

please help

I put the compiled path in Other Unit Files (for me this is ../dcpcrypt-2.0.4.1/lib/i386-linux)
I put the source path in Other Sources (for me this is ../dcpcrypt-2.0.4.1;../dcpcrypt-2.0.4.1/Ciphers;../dcpcrypt-2.0.4.1/Hashes)

But the values will depend on where you have the code.

jshand2010

  • Full Member
  • ***
  • Posts: 234
Re: How to use dcpcrypt??
« Reply #11 on: December 19, 2010, 07:05:05 am »
i really appreciate your help sfeinst.  thanks a million.

I got it all wording with the CBC method and works very well.  however after so many characters it doesn't seem to encrypt the whole text after about 20 characters.  can you show me how to encrypt everything that was typed into text boxes or memos?  thanks again
OpenSUSE Tumbleweed x86_64, Lazarus 2.2.0RC2 fixes branch, fpc 3.2.3 fixes branch

sfeinst

  • Full Member
  • ***
  • Posts: 186
Re: How to use dcpcrypt??
« Reply #12 on: December 19, 2010, 11:43:31 pm »
posting your code would help.  the steps I do were already posted, so if that is not working for you, I owuld need to see what you are attempting.

jshand2010

  • Full Member
  • ***
  • Posts: 234
Re: How to use dcpcrypt??
« Reply #13 on: January 01, 2011, 09:30:55 pm »
I don't use the LCL for it, but here is how I code using the library:

I add the following to uses:
DCPrijndael, DCPSha256

Then when loading data from a file (leaving out what I do with the data:
var
   Crypt: TDCP_rijndael;
   FileData: TFileStream;
        Data: TStringStream;
begin
  FileData := TFileStream.Create(Filename, fmOpenRead);
  Crypt := TDCP_rijndael.Create(nil);
  try
    Crypt.InitStr(Self.Password, TDCP_sha256);   // self-Password is the password used to save the file
    Crypt.DecryptStream(FileData, Data, FileData.Size);
    Crypt.Burn;
    // I then use Data as if it was not encrypted
   ...
  finally
    FreeAndNil(Crypt);
    FreeAndNil(Data);
    FreeAndNil(FileData);
  end;


to save a file I do the following:

var
   Crypt: TDCP_rijndael;
   FileData: TFileStream;
   Data: TStringStream;
begin
  FileData := TFileStream.Create(Filename, fmCreate);
  Data := TStringStream.Create('');
  Crypt := TDCP_rijndael.Create(nil);
  try
    // I write data out to a stream
  ...
    // then using that stream, I encrypt it to a file
    Crypt.InitStr(Self.Password, TDCP_sha256);
    Crypt.EncryptStream(Data, FileData, Data.Size);
    Crypt.Burn;
  finally
    FreeAndNil(Crypt);
    FreeAndNil(Data);
    FreeAndNil(FileData);
  end;


i have no idea on how this code works or how to implement the data into arrays etc...
OpenSUSE Tumbleweed x86_64, Lazarus 2.2.0RC2 fixes branch, fpc 3.2.3 fixes branch

ezlage

  • Guest
Re: How to use dcpcrypt??
« Reply #14 on: September 02, 2011, 10:34:52 pm »
This way works for me:

Code: [Select]
function Codifica(chave:string; texto:string; nivel:integer):string; {$ifndef linux} stdcall; {$else} cdecl; {$endif} //Encode(key, text, level)
  var
    motor: TDCP_blowfish;
    i: integer;
    t: string;
  begin
    if nivel=0
      then nivel:=1
      else if nivel>2
        then nivel:=2;
    motor:=TDCP_blowfish.Create(nil);
    t:=texto;
    for i:=1 to nivel do begin
      motor.InitStr(chave,TDCP_sha256);
      t:=motor.EncryptString(t);
      motor.Burn;
    end;
    result:=t;
    motor.Free;
  end;

function Decodifica(chave:string; codigo:string; nivel:integer):string; {$ifndef linux} stdcall; {$else} cdecl; {$endif} //Decode(key, text, level)
  var
    motor: TDCP_blowfish;
    i: integer;
    t: string;
  begin
    if nivel=0
      then nivel:=1
      else if nivel>2
        then nivel:=2;
    motor:=TDCP_blowfish.Create(nil);
    t:=codigo;
    for i:=1 to nivel do begin
      motor.InitStr(chave,TDCP_sha256);
      t:=motor.DecryptString(t);
      motor.Burn;
    end;
    result:=t;
    motor.Free;
  end;

 

TinyPortal © 2005-2018