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

  • Home
  • SEARCH
  • 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 868951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:13:42+00:00 2026-05-15T10:13:42+00:00

Given two classes: First class performs AES encryption / decryption and returns encrypted /

  • 0

Given two classes:

First class performs AES encryption / decryption and returns encrypted / decrypted data given a certain key and chain.

Second class gathers data to be encrypted and then passes it to the encryption / decryption class.

Is it proper design to call directly the encryption class from the class that gathers the data or should there be an object between the two classes which abstracts the process further? Should I have one abstract class instance and one encryption instance to handle all of these types of requests during the program’s lifetime?

  • 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-05-15T10:13:43+00:00Added an answer on May 15, 2026 at 10:13 am

    Personally, I would create some kind of abstract interface representing an encryption algorithm, with a factory function taking the key and producing a concrete instance of an encryption algorithm with a key installed. So the ‘second class’ here would call directly to the ‘first class’, but there would be a ‘third class’ in charge of instantiating the class. Something like:

    /* Core encryption framework definitions */
    class CipherInstance {
      // ...
      public:
        virtual void encrypt(void *, size_t) = 0;
        virtual void decrypt(void *, size_t) = 0;
        virtual size_t blocksize() const = 0;
    // ...
        virtual ~CipherInstance() { }
    };
    
    class Cipher {
      public:
        virtual CipherInstance *instantiate(const void *key, size_t keylen) = 0;
        virtual size_t minkeysize() const = 0;
        virtual size_t maxkeysize() const = 0;
    };
    
    /* AES implementation */
    class privateAESImpl : public Cipher { /* ... */ };
    // This is the only public definition in the AES implementation. The privateAESImpl
    // class is a stateless singleton, and this is the only instance. Doing this instead
    // of static functions allows AES to be passed to a function taking a Cipher * 
    extern privateAESImpl AES;
    
    // Much later:
      CipherInstance *aes = AES.instantiate(key, keylen);
      aes->encrypt(data, datalen);
    // or, to be more general:
    void frob(Cipher *cipher, void *key, size_t keylen, void *data, size_t datalen) {
        CipherInstance *inst = cipher->instantiate(key, keylen);
        inst->encrypt(data, datalen);
    }
    

    C#’s System.Security.Cryptography libraries use a similar approach – see, eg, System.Security.Cryptography.SymmetricAlgorithm. Note however that since C# supports introspection, there’s no need for a factory class – instead there’s simply a static method taking a name. With C++ a full factory class is needed.

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

Sidebar

Ask A Question

Stats

  • Questions 511k
  • Answers 511k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can set the AutoGenerateColumns-Property of the Grid to False… May 16, 2026 at 5:24 pm
  • Editorial Team
    Editorial Team added an answer I asked a quite related question on SO: How to… May 16, 2026 at 5:24 pm
  • Editorial Team
    Editorial Team added an answer Take a look at the following links: http://social.msdn.microsoft.com/Forums/en-US/vsarch/thread/a1ee9393-8f9b-45f2-8277-6e49346a119a Sneak peek… May 16, 2026 at 5:24 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I am working on a simple Core Data app. I have two classes: Client
I have created two partial classes for a web page. Now i have given
In C++, I have a certain template function that, on a given condition, calls
Given the classes Company , Employee , and Car what is the preferred practice
I'm pretty new to python. This is my first time working with classes in
We were just assigned a new project in my data structures class -- Generating
Given an Entity Data Model (EDMX) with Code Generation Strategy set to None, how
In a visual studio 2008 solution, I have two versions of the same class
I have two classes. Looking to be able to grab a variable that is
I'm having trouble trying to implement a shared method/property between two classes created by

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.