Topic: MAC ID and others

Hi,


I am planning a multi user Application for our production statistics.


Is it possible to get the MAC ID from a Network Adapter? I would like to use the MAC ID for identifying the single users and for automatic logon for restricted users. Using the Hard Disk ID would not work because its for production statistics and for security reasons some people have a better feeling for using the MAC ID.


Does somebody has an encryption source code I can use for encrypting data? XOR is not suitable/safe enough. Anything like RC4/Spritz, Rabbit or RC5? Datas are only important for around 120 hrs. After this time they are worthless, but should be encrypted/secured for this time.

Re: MAC ID and others

Hello.


Please download latest beta version
https://www.dropbox.com/s/eef9rf7u08k63 … b.zip?dl=0



Example, how to get info about all network adapters

procedure Form1_OnShow (Sender: string; Action: string);
var
  slMac: TStringList;
  slFriendlyName: TStringList;
  slDescription: TStringList;
  slType: TStringList;
begin
  slMac := TStringList.Create;
  slFriendlyName := TStringList.Create;
  slDescription := TStringList.Create;
  slType := TStringList.Create;


  if GetAdaptersInfo(slMac, slFriendlyName, slDescription, slType) then
  begin
      Form1.mmMac.Lines := slMac;
      Form1.mmFriendlyName.Lines := slFriendlyName;
      Form1.mmDescription.Lines := slDescription;
      Form1.mmType.Lines := slType;
  end;

  slMac.Free;
  slFriendlyName.Free;
  slDescription.Free;
  slType.Free;
end;

also you can use simple function GetFirstMacAddress to get MAC address of first adapter.



I have added function to encrypt/decrypt file or text using RC5 algorithm. Example:

procedure Form1_bEncrypt_OnClick (Sender: string; var Cancel: boolean);
begin
    Form1.Memo1.Text := EncryptRC5(Form1.Memo1.Text, Form1.edKey.Text);
end;

procedure Form1_bDecrypt_OnClick (Sender: string; var Cancel: boolean);
begin
    Form1.Memo1.Text := DecryptRC5(Form1.Memo1.Text, Form1.edKey.Text);
end;


procedure Form1_bEncryptFile_OnClick (Sender: string; var Cancel: boolean);
begin
    if EncryptFileRC5(Form1.edFileName.Text, Form1.edKey2.Text) then ShowMessage('Successful') else ShowMessage('Something wrong');
end;

procedure Form1_bDecryptFile_OnClick (Sender: string; var Cancel: boolean);
begin
    if DecryptFileRC5(Form1.edFileName.Text, Form1.edKey2.Text) then ShowMessage('Successful') else ShowMessage('Something wrong');
end;

Also you can download project examples:

Post's attachments

Attachment icon Encrypt RC5.zip 4.29 kb, 495 downloads since 2017-10-23 

Attachment icon GetAdaptersInfo.zip 3.72 kb, 618 downloads since 2017-10-23 

Dmitry.

3 (edited by teco049 2017-10-24 09:38:52)

Re: MAC ID and others

Wow,


I am really impressed.

Asking for some new features and in less 24 hrs - here they are.

Absolutlely awesome.

Many, many thanks.


Edit:
There is a little bug: Please see attached. I have add some functions:

Database: A small part of the encrypted text is not correct in the database. Decryption fails if read from database. (Use the sample text, encrypt it, write it to database, read it back - text will be a little bit shorter, decrypt it and at the end some text is not correctly decrypted.)


Mime/Base64: To prevent these problems I have tried to encode it as Base64. But it does not work completely with UTF-8 Text. Any idea why?


HEX: Original Text is converted to Hex with xx Values. The encrypted text as xxxx Unicode Values. I have used an example from the Forum. Any idea how to update for encrypted unicode?


Thank you.


Just for the documentation in our company: How many rounds are you using? (RC5-w/r/b)

Every implementation is over the requested 120hrs. The information is only to make our statistik guru happy. smile


Thank you.

Post's attachments

Attachment icon Encrypt RC5.zip 9.76 kb, 446 downloads since 2017-10-24 

Re: MAC ID and others

Dear Dmitry,


I have done some tests:


File encryption works so far.


Text encryption in a Memo field works, but if used to store in a database field or string variable it does not work. Please see attached, there are some test to show you the difference.


Encrypted string to hex: Solution found, but only if first encrypted in a Memo field. No solution if encrypted in a string variable.


Hope it helps you to find out what I have done wrong.


Target is that I convert the encrypted string to Base64 and store the Base64 in a Database. When reading I convert everything back.

Post's attachments

Attachment icon Encrypt RC5.zip 10.87 kb, 472 downloads since 2017-10-24 

Re: MAC ID and others

I have tried to solve it, but without success, I will try again later.

Dmitry.

Re: MAC ID and others

Replace the script with my version!


Delphi XE editions have a bug with String and ANSI/UTF8 Mode switching.


String has dual definition. ANSI and UTF8


Form Element Memo is designed UTF8. So Encryption and Decryption works without problem.


At the script you can see that it will work if you do encryption at the Memo Field and transfer encrypted content to String. String get the internal information to switch to UTF8 Mode.


Base64 not tested, but if you search for "UTF8 to Base64 Delphi Source Code" you get various information for a converting problem with Delphi XE editions with UTF8 and Base64. For correct converting you need a few lines more code to convert String to Widestring and telling the internal Base64 function to switch to UTF8 Mode instead of ANSI Mode.


Or you try to find a complete source code.


Use online converter for testing.


For converting String variables you need to bring String fixed to UTF8 Mode or you convert it direcly to Base64. This would result the following structure:

EncryptRC5(Content : String, Key : String) : Base64
DecryptRC5(Content : Base64, Key : String) : String   (or WideString)


You can see the switching problem on the text4 variable: The length is double as from the text1 variable.  UTF8 has two bytes, ANSI one byte. String is not correclty catching the mode switching. And this results also in the problem, that the Database does not get the right information what to store. ANSI or UTF.


Delphi 10 editions have a better switching selection for String.


Expensive - maybe Lazarus would be interesting and cheaper to look into....

Post's attachments

Attachment icon script.pas 6.2 kb, 622 downloads since 2017-10-26