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 8519007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:07:52+00:00 2026-06-11T06:07:52+00:00

I have encryption decryption code in C#, VB.net and VC++ (VS 2008) and encrypted

  • 0

I have encryption decryption code in C#, VB.net and VC++ (VS 2008) and encrypted file by anyone of this can be decrypted by anyone.

Now the requirement is, I have to use VC++ (VS 2008) static lib file in VC++ 6.0.

OR suggest any other alternative to do this(without dll)

namespace RijndaelEncDec
{

    void Rijndael::LN_EncryptFile(String^ fileSource, String^ fileDestination, String^ password)
    {
        // Declare the streams used
        // to encrypt to an in memory
        // array of bytes.

        CryptoStream^   cryptoStream;

        FileStream^ fsIn;
        FileStream^ fsOut ;

        // Declare the RijndaelManaged object
        // used to encrypt the data.
        RijndaelManaged^ RijndaelCipher;

        try
        {           
            fsIn=gcnew FileStream(fileSource, FileMode::Open, FileAccess::Read);
            fsOut = gcnew FileStream(fileDestination, FileMode::Create, FileAccess::Write);


            array<Byte>^  salt = gcnew array<Byte>(13){ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0xF1, 0xF0, 0xEE, 0x21, 0x22, 0x45 };
            Rfc2898DeriveBytes ^secretKey =gcnew Rfc2898DeriveBytes(password,salt);

            RijndaelCipher = gcnew RijndaelManaged();
            RijndaelCipher->Padding = PaddingMode::PKCS7;
            RijndaelCipher->Mode=CipherMode::CBC;
            RijndaelCipher->BlockSize=128;
            RijndaelCipher->Key = secretKey->GetBytes(32);
            RijndaelCipher->IV = secretKey->GetBytes(16);


            ICryptoTransform^ encryptor = RijndaelCipher->CreateEncryptor();
            cryptoStream = gcnew CryptoStream(fsOut, encryptor, CryptoStreamMode::Write);


            int ByteData;
            while ((ByteData=fsIn->ReadByte()) != -1)
            {
              cryptoStream->WriteByte(ByteData);
            }

          cryptoStream->FlushFinalBlock();

        }
         catch (FileNotFoundException^ ex)
            {
                if ((ex->FileName->CompareTo(fileSource) == 0) && (GlobalVariableClass::logPermission == true))
                {
                    StreamWriter^ writer = gcnew StreamWriter(GlobalVariableClass::logFileLocation);
                    writer->WriteLine(ex->Message);
                    writer->Close();
                }
                if ((ex->FileName->CompareTo(fileDestination) == 0) && GlobalVariableClass::logPermission == true)
                {
                    StreamWriter^ writer = gcnew StreamWriter(GlobalVariableClass::logFileLocation);
                    writer->WriteLine(ex->Message + " i.e. Input file for Encryption");
                    writer->Close();
                }

            }
         catch (Exception^ ex)
            {
                if(GlobalVariableClass::logPermission==true)
                {
                    StreamWriter^ writer = gcnew StreamWriter(GlobalVariableClass::logFileLocation);
                    writer->WriteLine(ex->Message + " During Encrypting File");
                    writer->Close();

                }


            }
        finally
        {


            // Close the streams.

            if (cryptoStream)
                cryptoStream->Close();
            if(fsIn)
                fsIn->Close();
            if(fsOut)
                fsOut->Close();
            // Clear the RijndaelManaged object.
            if (RijndaelCipher)
                RijndaelCipher->Clear();
        }

        // Return the encrypted bytes from the memory stream.
        return ;//msEncrypt->ToArray();
    }

    void Rijndael::DecryptFile(String^ fileSource, String^ fileDestination, String^ password)
    {



        array<Byte>^  salt = gcnew array<Byte>(13) { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0xF1, 0xF0, 0xEE, 0x21, 0x22, 0x45 };
        Rfc2898DeriveBytes ^secretKey =gcnew Rfc2898DeriveBytes(password,salt);       

        CryptoStream^ csDecrypt;
        StreamReader^ srDecrypt;
        FileStream^ fsIn;
        FileStream^ fsOut;

        // Declare the RijndaelManaged object
        // used to decrypt the data.
        RijndaelManaged^ RijndaelCipher;



        try
        {

            fsIn  = gcnew FileStream(fileSource, FileMode::Open, FileAccess::Read);
            fsOut = gcnew FileStream(fileDestination, FileMode::Create, FileAccess::Write);   

            RijndaelCipher = gcnew RijndaelManaged();
            RijndaelCipher->Padding = PaddingMode::PKCS7;
            RijndaelCipher->Key = secretKey->GetBytes(32);
            RijndaelCipher->IV = secretKey->GetBytes(16);

            // Create a decrytor to perform the stream transform.
            ICryptoTransform^ decryptor = RijndaelCipher->CreateDecryptor();

            // Create the streams used for decryption.

            csDecrypt = gcnew CryptoStream(fsOut, decryptor, CryptoStreamMode::Write);

            int ByteData;
            while ((ByteData=fsIn->ReadByte()) != -1)

            {

              csDecrypt->WriteByte(ByteData);

            }





        }
         catch (FileNotFoundException^ ex)
                {
                    if ((ex->FileName->CompareTo(fileSource) == 0) && (GlobalVariableClass::logPermission == true))
                    {

                        StreamWriter^ writer = gcnew StreamWriter(GlobalVariableClass::logFileLocation);
                        writer->WriteLine(ex->Message + " i.e. Input file for decryption");
                        writer->Close();
                    }
                    if ((ex->FileName->CompareTo(fileDestination) == 0) && GlobalVariableClass::logPermission == true)
                    {
                        StreamWriter^ writer = gcnew StreamWriter(GlobalVariableClass::logFileLocation);
                        writer->WriteLine(ex->Message + " i.e. Output file while decryption");
                        writer->Close();
                    }

                }
                catch (Exception^ ex)
                {
                    if (GlobalVariableClass::logPermission == true)
                    {
                        StreamWriter^ writer = gcnew StreamWriter(GlobalVariableClass::logFileLocation);
                        writer->WriteLine(ex->Message + " During Decrypting File");
                        writer->Close();
                    }

                }
        finally
        {
            // Clean things up.

            // Close the streams.
            if (srDecrypt)
                srDecrypt->Close();
            if (csDecrypt)
                csDecrypt->Close();

               fsIn->Close();
               fsOut->Close();


            // Clear the RijndaelManaged object.
            if (RijndaelCipher)
                RijndaelCipher->Clear();
        }

        return ;
    }

    String^ Rijndael:: ReadEncryptFileToBuffer(String^ fileSource,[System::Runtime::InteropServices::OutAttribute]  String ^% buffer,String^ password)
    {
        FileStream^ fsIn; 
        MemoryStream^ memoryStream;
        CryptoStream^ cryptoStream;
        StreamReader^ fileReader,^streamReader;
        RijndaelManaged^ RijndaelCipher;
        String^ decryptText;

         // First we are going to open the file streams
        try
        {
          RijndaelCipher = gcnew RijndaelManaged();
          RijndaelCipher->Mode = CipherMode::CBC;
          RijndaelCipher->KeySize = 256;
          RijndaelCipher->BlockSize = 128;
          RijndaelCipher->Padding = PaddingMode::PKCS7;

          fsIn = gcnew FileStream(fileSource, FileMode::Open, FileAccess::Read);
          fileReader = gcnew StreamReader(fsIn,System::Text::Encoding::Default);
          String^ cipherText = fileReader->ReadToEnd();
          array<Byte>^ cipherByte = System::Text::Encoding::Default->GetBytes(cipherText);



          array<Byte>^  salt = gcnew array<Byte>(13) { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0xF1, 0xF0, 0xEE, 0x21, 0x22, 0x45 };  
          Rfc2898DeriveBytes^ secretKey = gcnew Rfc2898DeriveBytes(password, salt);
          ICryptoTransform^ Decryptor = RijndaelCipher->CreateDecryptor(secretKey->GetBytes(32), secretKey->GetBytes(16));





          memoryStream = gcnew MemoryStream(cipherByte);
          cryptoStream = gcnew CryptoStream(memoryStream, Decryptor, CryptoStreamMode::Read);
          streamReader = gcnew StreamReader(cryptoStream);
          decryptText = streamReader->ReadToEnd();
          buffer = decryptText;
          Console::WriteLine(decryptText);



        }
         catch (FileNotFoundException^ ex)
        {
            if (ex->FileName->CompareTo(fileSource) == 0 && GlobalVariableClass::logPermission == true)
            {

                StreamWriter^ writer = gcnew StreamWriter(GlobalVariableClass::logFileLocation);
                writer->WriteLine(ex->Message + " i.e. Input file for decryption Buffer");
                writer->Close();

            }


        }
        catch (Exception^ ex)
        {
            if (GlobalVariableClass::logPermission == true)
            {
                StreamWriter^ writer = gcnew StreamWriter(GlobalVariableClass::logFileLocation);
                writer->WriteLine(ex->Message + "i.e. During Reading Encrypting File to Decrypted Buffer");
                writer->Close();
            }

        }
        finally
        {
          if(fsIn)
          fsIn->Close();
          if(memoryStream)
          memoryStream->Close();
          if(cryptoStream)
          cryptoStream->Close();
          if(streamReader)
          streamReader->Close();

        }
        return decryptText;
    }

    void Rijndael::WriteEncFileFromDecBuffer(String^ buffer, String^ fileDestination, String^ password)
    {
        FileStream^ fsOut; 
        CryptoStream^ cryptoStream;
        StreamReader^ streamReader;

        try
        {
            RijndaelManaged^ RijndaelCipher = gcnew RijndaelManaged();
            RijndaelCipher->Mode = CipherMode::CBC;
            RijndaelCipher->KeySize = 256;
            RijndaelCipher->BlockSize = 128;
            RijndaelCipher->Padding = PaddingMode::PKCS7;

            FileStream^ fsOut = gcnew FileStream(fileDestination, FileMode::Create, FileAccess::Write);

            array<Byte>^  salt = gcnew array<Byte>(13) { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0xF1, 0xF0, 0xEE, 0x21, 0x22, 0x45 };
            array<Byte>^ plainText = System::Text::Encoding::Default->GetBytes(buffer);
            Rfc2898DeriveBytes^ secretKey = gcnew Rfc2898DeriveBytes(password, salt);
            ICryptoTransform^ Encryptor = RijndaelCipher->CreateEncryptor(secretKey->GetBytes(32), secretKey->GetBytes(16));

            cryptoStream = gcnew CryptoStream(fsOut, Encryptor, CryptoStreamMode::Write);

            cryptoStream->Write(plainText, 0, plainText->Length);

            cryptoStream->FlushFinalBlock();
            cryptoStream->Close();
            fsOut->Close();
        }

        catch(FileNotFoundException^ ex)
        {
            if ( GlobalVariableClass::logPermission == true)
            {

                StreamWriter^ writer = gcnew StreamWriter(GlobalVariableClass::logFileLocation);
                writer->WriteLine(ex->Message + " i.e. Output file from Dencrypted Buffer");
                writer->Close();
            }

        }
        catch(Exception^ ex)
        {
            if (GlobalVariableClass::logPermission == true)
            {
                StreamWriter^ writer = gcnew StreamWriter(GlobalVariableClass::logFileLocation);
                writer->WriteLine(ex->Message + " During Writing Encrypting File from Decrypted Buffer");
                writer->Close();

            }
        }
        finally
        {
          fsOut->Close();
          cryptoStream->Close();
          streamReader->Close();

        } 
    }
}
  • 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-11T06:07:54+00:00Added an answer on June 11, 2026 at 6:07 am

    You cannot do this. VS6 was before .NET even existed, and thus you need to provide an interface to the managed component that is accessible from technologies VS6 is aware of. The two simplest options:

    1. Create a COM interface for the managed library and use that from C++
    2. Create a C-style interface and use that from C++. Not a C++ interface because of issues crossing DLL boundaries with C++ objects and features.

    I don’t understand the requirement of needing a .lib file though; neither of the obvious solutions would employ this. You should be clearer why you “need” a .lib if you want a better answer. The problem is you have an impossible set of requirements:

    1. You cannot use a DLL (limiting yourself to only one PE module)
    2. Managed and unmanaged cannot co-exist in the same PE.
    3. VS6 cannot write managed code.

    These 3 restrictions prove it’s impossible as you want; you will need to compromise somewhere.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .NET class that implements TripleDES encryption and decryption. The code is
i have a java program . this is a AES encryption - decryption program.
I have been doing some research on creating an encryption/decryption class for use in
Hi Have use this code before. Find it useful on Web. But Dont know
I have made simple encryption/decryption method in php that I'm trying to move to
I need a CORE that will perform AES-128 Encryption/Decryption. I have searched online but
I have this Telerik radgrid | Encryption Key | Password to encode | Edit
I was trying to use XTEA encryption on NETMF using the code from blog
In C, I have a function that implements both the encryption and decryption routines
I have an mcrypt encryption and decryption routine within one of my Android apps.

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.