我对openssl很陌生,我想知道openssl版本是否有所不同 我有加密的Txt文件,可以使用在OpenSuse linux上运行的Openssl版本1.1.0i-fips进行解密。但是,当我在我的Mabook上使用openssl版本1.0.2p尝试相同的程序时,我无法解密文本文件。为什么呢??谁能帮忙。
这是我的程序,它读取同一目录中的所有4个txt文件
#include <fcntl.h> /* O_RDONLY */
#include <stdio.h> /* printf */
#include <string.h> /* memcpy */
#include <unistd.h> /* read */
#include <openssl/idea.h> /* idea_* */
unsigned char input[512]; /* for encrypted text */
unsigned char output[512]; /* for decrypted text */
unsigned char key[16] = { /* 128 bit key */
0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF};
static unsigned char iv[8] = { /* 64 bit IV block */
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef};
int main(void)
{
int i, n, t1, t2, t3, t4;
long length;
IDEA_KEY_SCHEDULE encrypt_ks, decrypt_ks;
unsigned char tmp[8];
//Key anlegen
idea_set_encrypt_key(key, &encrypt_ks);
idea_set_decrypt_key(&encrypt_ks, &decrypt_ks);
/* open the given text files */
t1 = open("text1.bin", O_RDONLY);
t2 = open("text2.bin", O_RDONLY);
t3 = open("text3.bin", O_RDONLY);
t4 = open("text4.bin", O_RDONLY);
if ((t1 | t2 | t3 | t4) < 0) {
perror("text[1-4].bin");
return 1;
}
length = 512;
/* read 512 bytes from file t4 */
read(t4, input, length);
/* ... decrypt input in ECB mode */
for(i = 0; i < 512; i += 8)
{
idea_ecb_encrypt(&input[i], &output[i], &encrypt_ks);
}
/* show decrypted text on stdout */
printf("Text 4 == %s\n\n", output);
// Text 1 ===============================================
read(t1, input, length);
/* ... decrypt input in CBC mode */
//Initialiserung vektor ändert sich deswegen tmp benutzen vor jeder verwednung
memcpy(tmp,iv,8);
idea_cbc_encrypt(input, output,length,&decrypt_ks,tmp,IDEA_DECRYPT);
printf("Text 1 == %s\n\n", output);
// Text 2 ===============================================
read(t2, input, length);
/* ... decrypt input in CFB mode */
memcpy(tmp,iv,8);
//Blockgrenze setzen
n = 0;
idea_cfb64_encrypt(input, output, length, &encrypt_ks, tmp,&n,IDEA_DECRYPT);
printf("Text 2 == %s\n\n", output);
// Text 3 ===============================================
read(t3, input, length);
memcpy(tmp,iv,8);
idea_ofb64_encrypt(input, output, length, &encrypt_ks, tmp, &n);
/* ... decrypt input in OFB mode */
printf("Text 3 == %s\n\n", output);
return 0;
}