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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:44:27+00:00 2026-05-24T13:44:27+00:00

i need to decrypt some cypherd text (aes 128 ctr) programming in C using

  • 0

i need to decrypt some cypherd text (aes 128 ctr) programming in C using openssl, since libraries version i’m using don’t support EVP for aes ctr i’m tring to use AES_ctr128_encrypt(), but i get segmentation fault, here’s the code i’m using:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <openssl/aes.h>

int chartoint(char car);
char * extochar(char * in, int inLen);

struct ctr_state { 
    unsigned char ivec[16];   
    unsigned int num; 
    unsigned char ecount[16]; 
}; 

void init_ctr(struct ctr_state *state, const unsigned char iv[16]){
    state->num = 0; 
    memset(state->ecount, 0, 16); 
    memcpy(state->ivec, iv, 16);
} 

void main(){
    unsigned char * cypher = extochar("874d6191b620e3261bef6864990db6ce",32);
    unsigned char * key = extochar("2b7e151628aed2a6abf7158809cf4f3c",32);
    unsigned char * iv = extochar("f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff",32);
    unsigned char out[256]; //more than needed
    AES_KEY aes_key;
    int msg_len = 16;
    struct ctr_state status; 

    if (!AES_set_encrypt_key(key, 16, &aes_key)){
        printf("key error"); 
        exit(-1);
    }

    init_ctr(&status, iv);

    AES_ctr128_encrypt(cypher, out, msg_len, &aes_key, status.ivec, status.ecount, &status.num);
//expected plaintext: "6bc1bee22e409f96e93d7e117393172a"
}

segmentation fault is on istruction AES_ctr128_encrypt(), the last one, while i’m expecting “6bc1bee22e409f96e93d7e117393172a” as plaintext (using printf(“%02x”, var[i]) to printf it)

  • 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-24T13:44:28+00:00Added an answer on May 24, 2026 at 1:44 pm

    Your AES key is 256 bits long. You tell AES_set_encrypt_key that it’s 16 bits. And then you pass the key to AES_ctr 128 _encrypt. Your code would work a lot better if all three of those numbers were the same.

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

Sidebar

Related Questions

I have an encrypted bit of text that I need to decrypt. It's encrypted
I'm using DPAPI in C++ to encrypt some data that I need to store
I need to decrypt some data that has been 3des encoded on system running
So I need to be able to actually decrypt the password because some old
I need a simple encryption for some text strings. I want to create coupon
I need to decrypt some data files with wincrypt and examples are few and
I'm trying to encrypt/decrypt files with PBE using AES. I'm using Bouncy Casle library(lightweight
In my Python web app, I would need to decrypt a file that was
I need to encrypt / decrypt passwords for a new application. The spec requires
I need to encrypt and decrypt a querystring in ASP.NET. The querystring might look

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.