Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9253273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:10:39+00:00 2026-06-18T11:10:39+00:00

So my current task involves taking a given string of text (Ex: ABC123) and

  • 0

So my current task involves taking a given string of text (Ex: ABC123) and encrypting it using LockBox3’s EncryptString(source, target) function. I can successfully encrypt the string and get the output to save to a .txt file.

The next step in this process is to then use LockBox3’s EncryptFile(source, target) function to take the .txt containing my already-encrypted string and encrypting said file using AES-128 (same as the string encryption but with diff password)

Basically, I can get the string to encrypt correctly and output to a .txt file. I then request that the user grab the .txt, and bring it into my program. The program then attempts to take that file and encrypt it further. When I do this, I get a file to output.. however when I go to decrypt said file the resulting .txt does not contain the original text.. or any text for that matter. I am basically confused as to how I should be going about encrypting the .txt file. Any suggestions? I apologize if this question/code is not specific enough. Please let me know what else, if anything I need to make clear about the situation in order to better help you guys understand what I’m struggling with! Thanks!

EDIT1:

Alright everyone, thanks for the suggestions. To clarify:

The stream I have in the decryption process is to be used later, so that after I have decrypted the file, I can read from it and decrypt the remaining encrypted (from the first step) string.

To clarify further:

My codec (Codec1) for encrypting the string is using AES-128 with CBC, with a tag of “0” and an AsymetricKeySize of 1024 (which, Im pretty sure is irrelevant for this type of encryption correct?) My codec for encrypting FILES (Codec2 above) has the same settings, however the passwords for Codec1 and Codec2 are different. Basically, I am using Codec1 to encrypt a string and write it to a .txt, and then I am using Codec2 to encrypt said file.. eventually decrypt it and use the Stream to read from said file and decrypt that string using Codec1 again.

my file encryption/decryption code:

String Encryption:

procedure TForm1.Button1Click(Sender: TObject);
begin
  codec1.Password := WORD_1;
  //Begin encryption
  sPlainText := Serial_number.Number;         //Store Serial Number of machine 
  codec1.EncryptString(sPlainText,CipherText);   //Encrypt (base64)
  listbox2.Clear;
  listbox2.AddItem(Ciphertext, AnsiCipher);
  end;

Write encrypted string to a file and save it:

saveDialog := TSaveDialog.Create(self);
  saveDialog.Title := 'Choose location to save Authentication Code';
  saveDialog.InitialDir := 'C:\';
  saveDialog.DefaultExt := '';
  saveDialog.FilterIndex := 1;
  saveDialog.Execute();
  glb_fileName1 := saveDialog.FileName;
 //open stream and write cipher to a .txt of chosen location
  try
    Stream := TFileStream.Create(saveDialog.GetNamePath + saveDialog.FileName + '.txt', fmOpenReadWrite);
  except
    Stream := TFileStream.Create(saveDialog.GetNamePath + saveDialog.FileName + '.txt', fmCreate);
  end;
    for k := 1 to (Length(CipherText)) do
        buff[k] := byte(CipherText[k]);
    ptr := @buff[1];
    Stream.WriteBuffer(ptr^, Length(CipherText));
  Stream.Free;
  saveDialog.Free;

Grab location of .txt for file encryption:

procedure TForm1.Button4Click(Sender: TObject);
var
  fileName : string;
  holder_obj : TSerial_number;
begin
  holder_obj := Tserial_number.Create;
  listbox4.Clear;

if OpenTextFileDialog1.Execute() then
   fileName := OpenTextFileDialog1.FileName;     
   listbox4.AddItem(filename, holder_obj);
end;

File Encryption:

  Codec2.Password := WORD_2;
  sCrypt := glb_fileName1 + '_enc.txt';
  Codec2.EncryptFile(glb_fileName1+'.txt', sCrypt);

Grab Encrypted File for decryption:

procedure TForm1.Button3Click(Sender: TObject);
var
  holder_obj : TSerial_number;
begin
  holder_obj := Tserial_number.Create;
  listbox3.Clear;
if OpenTextFileDialog1.Execute() then
   glb_fileName2 := OpenTextFileDialog1.FileName;
   listbox3.AddItem(glb_filename2, holder_obj);
end;

File Decryption (opening a stream to read from the decrypted file once I have it, so that I can decrypt the encrypted string it contains):

procedure TForm1.Button5Click(Sender: TObject);
var
  saveDialog : TSaveDialog;
begin
  saveDialog := TSaveDialog.Create(self);
  saveDialog.Title := 'Choose location to save Decrypted Authentication Code';
  saveDialog.InitialDir := 'C:\';
  saveDialog.DefaultExt := '';
  saveDialog.Execute();
  glb_fileName1:= saveDialog.FileName;
 //open stream and write cipher to a .txt of chosen location
  try
    Stream := TFileStream.Create(saveDialog.GetNamePath + saveDialog.FileName + '.txt', fmOpenReadWrite);
  except
    Stream := TFileStream.Create(saveDialog.GetNamePath + saveDialog.FileName + '.txt', fmCreate);
  end;
  Stream.Free;

  Codec2.Password := WORD_2;
  Codec2.DecryptFile(glb_fileName2, saveDialog.FileName + '.txt');
  saveDialog.Free;
end;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T11:10:40+00:00Added an answer on June 18, 2026 at 11:10 am

    The code you provided is way to complicated to try and see what is going wrong. If you are just trying to see if the encoding/decoding works you should only need simple code like the code below. Just put a test file on your drive and hardcode the names. That will let you know that the encoding/decoding works if the InputFile.txt and Un-EncryptedFile.text are the same.

    Once you have the working then you can start to build up your full routines. The code you have posted is really confusing with the globals being used between the button clicks and just named 1, 2, etc. You have streams created that do nothing and only confuse the issue more. Strip things back to the basics and get that working first.

    procedure TestEncodeDecode();
    begin
      Codec2.Password := WORD_2;
      Codec2.EncryptFile('c:\InputFile.txt', 'c:\EncryptedFile.txt');
      Codec2.DecryptFile('c:\EncryptedFile.txt', 'c:\Un-EncryptedFile.txt');
    end;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was given the task of doing a facelift to our current site. I
My current task is taking a Java project written and developed in Ubuntu NetBeans
My current task is to secure a WCF service. The service is hosted using
Possible Duplicate: Activity not started, its current task has been brought to the front
The task is to make changes to current tables structure without recreating these tables.
My task is to write a class RFind which recursively searches the current directory
I have an NAnt task ship to package my current .sql scripts into a
I have a task killer program that has a listbox of current running processes.
current code (not working): /^script\s*type=\text\/javascript/i.test(tagName)
My current task is to develop a software for measurement and testing purposes which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.