c - openssl命令行解密aes ctr 128

标签 c encryption command-line openssl aes

我正在使用以下工作代码来解密文件:

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

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

FILE *fp;
FILE *rp;
FILE *op;
size_t count;   
char * buffer; 
AES_KEY key; 

int bytes_read, bytes_written;   
unsigned char indata[AES_BLOCK_SIZE]; 
unsigned char outdata[AES_BLOCK_SIZE];  
unsigned char ckey[] =  "1234567890123456"; 
unsigned char iv[8] = {0};
struct ctr_state state;   

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

void decrypt(){
  //Opening files where text cipher text is read and the plaintext recovered         
  rp=fopen("c:\\temp\\decrypted.mp3","wb");
  op=fopen("c:\\temp\\encrypted.mp3","rb");
  if (rp==NULL) {fputs ("File error",stderr); return;}   
  if (op==NULL) {fputs ("File error",stderr); return;} 

  //Initializing the encryption KEY
  AES_set_encrypt_key(ckey, 128, &key); 
    init_ctr(&state, iv);//Counter call

  //Encrypting Blocks of 16 bytes and writing the output.txt with ciphertext   
  while (1) {     
    bytes_read = fread(indata, 1, AES_BLOCK_SIZE, op);  
    AES_ctr128_encrypt(indata, outdata, bytes_read, &key, state.ivec, state.ecount, &state.num); 
    bytes_written = fwrite(outdata, 1, bytes_read, rp); 
    if (bytes_read < AES_BLOCK_SIZE) 
    break; 
    }   
  fclose (rp); 
  fclose (op);
}

int main(int argc, char *argv[]){   
  decrypt(); 
  return 0;
}

是否可以使用 openssl 命令行做同样的事情?

据我所知,没有 -aes-128-ctr 密码,但 openssl 中是否有任何等效密码?

最佳答案

我检查过的任何版本的 openssl(1) 命令行工具似乎都不支持任何密码的计数器模式。

关于c - openssl命令行解密aes ctr 128,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9434265/

相关文章:

c - 我将如何重构此 C 代码以消除重复

java - Java 6 中的密码证书命中不在 Java 7 中运行

command-line - grep 从文件的底部到顶部

command-line - 在不创建中间文件的情况下显示来自 Graphviz 的图像?

ruby-on-rails - 包括标签和其他无标签测试?

c - 使用指针 C 从函数返回数组

c - 如何从 C 中的 **argv 派生 argc

c - stdout 和 STDOUT_FILENO 的区别

php - 使用 PHP 在 MySQL 数据库中自动加密?

java - 来自公共(public)字符串的 Android RSA 加密