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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:17:02+00:00 2026-06-17T12:17:02+00:00

How could insert text by argument and automatically transform it to hex? I tried

  • 0

How could insert text by argument and automatically transform it to hex?

I tried with:

unsigned char aesKey[32] = argv[1];

but get errors

The output would be like this:

unsigned char aesKey[32] = {
    0x53, 0x28, 0x40, 0x6e, 0x2f, 0x64, 0x63, 0x5d, 0x2d, 0x61, 0x77, 0x40, 0x76, 0x71, 0x77, 0x28, 
    0x74, 0x61, 0x7d, 0x66, 0x61, 0x73, 0x3b, 0x5d, 0x66, 0x6d, 0x3c, 0x3f, 0x7b, 0x66, 0x72, 0x36
};

unsigned char *buf;

aes256_context ctx;
aes256_init(&ctx, aesKey);

for (unsigned long i = 0; i < lSize/16; i++) {
    buf = text + (i * 16);
    aes256_encrypt_ecb(&ctx, buf);
}

aes256_done(&ctx);

Thanks in advance

  • 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-17T12:17:03+00:00Added an answer on June 17, 2026 at 12:17 pm

    In C and C++, when you have code like

    char name[]="John Smith";
    

    The compiler knows at compile time what the size of that char array, and all the values will be. So it can allocate it on the stack frame and assign it the value.

    When you have code like
    char * strptr = foo();
    char str[] = strptr;

    The compiler doesn’t know what the size and value of the string pointed by strptr is. That is why this is not allowed in C/C++.

    In other words, only string literals can be assigned to char arrays, and that too only at the time of declaration.

    So

    char name[] = "John Smith";
    

    is allowed.

    char name[32];
    name = "John Smith";
    

    is not allowed.

    Use memcpy

    So you could use memcpy. (Or use c++ alternative that others have alluded to)

    unsigned char *aesKey;
    size_t len = (strlen(argv[1])+1)*sizeof(unsigned char);
    aesKey = malloc(len);
    memcpy(aesKey, argv[1], len);
    

    The old solution

    (here is my previous answer, the answer above is better)
    So you need to use strncpy.

    unsigned char aesKey[32];
    strncpy((char *) aesKey, argv[1], 32);
    

    Notice the routine is strncpy not strcpy. strcpy is unsafe. (Thanks PRouleau for the arg fix)

    If strncpy is not available in Visual Studio then you may have to try strcpy_s (Thanks Google: user:427390)

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

Sidebar

Related Questions

Could someone post some sample code showing how to insert text greater than 4000
I' ve got a short question. How could I insert values contain a datetime
Could anyone tell me how to bulk insert data from a ref cursor to
Could somebody explain what I'm doing wrong in attempting to insert a new UITableViewCell?
In MySql I could have a table with an auto increment column and insert
Ok, I couldn't insert the overview image, but I'm required to create a PHP
How using VSTO and Word 2003 can I insert text after a table I've
How I could achieve batch update/insert using SQLCommand . I wanted to create SQLCommand
I am trying to draw/print a text, but i need a transparent background. I
I'm trying to create my Dog and add categories to it but I get

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.