用于解密aes ctr 128的openssl命令行
我正在使用以下工作代码解密文件:用于解密aes ctr 128的openssl命令行,c,encryption,command-line,openssl,aes,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;
#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;
}
#包括
#包括
#包括
结构中心状态{
无符号字符ivec[16];
无符号整数;
无符号字符计数[16];
};
文件*fp;
文件*rp;
文件*op;
大小/数量;
字符*缓冲区;
AES_密钥;
读取整数字节,写入字节;
无符号字符indata[AES_BLOCK_SIZE];
无符号字符输出数据[AES_块大小];
无符号字符ckey[]=“1234567890123456”;
无符号字符iv[8]={0};
结构中心状态;
void init_ctr(struct ctr_state*state,const unsigned char iv[8]){
状态->数值=0;
memset(state->ecount,0,16);
memset(状态->ivec+8,0,8);
memcpy(州->ivec,iv,8);
}
void decrypt(){
//打开读取文本密文并恢复明文的文件
rp=fopen(“c:\\temp\\decrypted.mp3”,“wb”);
op=fopen(“c:\\temp\\encrypted.mp3”、“rb”);
if(rp==NULL){fputs(“文件错误”,stderr);return;}
if(op==NULL){fputs(“文件错误”,stderr);return;}
//初始化加密密钥
AES设置加密密钥(ckey、128和密钥);
init_ctr(&state,iv);//计数器调用
//加密16字节的块并使用密文写入output.txt
而第(1)款{
字节读取=fread(indata,1,AES块大小,op);
AES加密(indata、outdata、字节读取和密钥、state.ivec、state.ecoount和state.num);
bytes_write=fwrite(outdata,1,bytes_read,rp);
if(字节读取
是否可以使用openssl命令行执行相同的操作
好了,没有-aes-128-ctr密码,但是openssl中有任何等效的吗?我检查过的openssl(1)命令行工具的任何版本似乎都不支持任何密码的计数器模式