Frage

Ich schreibe ein Programm, das die Boneh-Franklin-Identitätsbasis implementiert. Für die tatsächlichen Verschlüsselungsmethoden verwende ich Blowfish, von denen ich (https://voltar.org/). Ich versuche, den Blowfish -Verschlüsselungs-/Entschlüsselungscode an mein Programm anzupassen. Der Unterschied in meinem Programm besteht darin, dass ich die Nachricht aus der Standardeingabe gelesen, verschlüsselt und die Verschlüsselung ausdrucken, dann entschlüsselt und die Entschlüsselung ausdrucken (die die ursprüngliche Nachricht sein sollte). Derzeit habe ich die Eingabenachricht bis zu einem "?" Zeichen und dann versuchen Sie, dem Code von der Website zu folgen. Die Entschlüsselung wird jedoch als unlesbare Zeichen gedruckt. Ich habe versucht, dieses Problem zu lösen, aber ich bin stecken geblieben. Kannst du mir bitte helfen?

//initializations

BF_KEY s_key;       //shared key of the blowfish encryption
char plain[1000000];    //the plaintext of the message
char cipher[1000000];   //the ciphertext of the message  
char byte;          //to hold the byte of the msg
char *token;        //points to tokens of the msg
char IV[8]="MY*IV000";  //the initialization vector
int offset = 0;     //the offset of encryption
int b_count = 0;        //number of bytes in d_buf
char block[8];      //blocks of encryption
char msg[1000000];      //the input msg from the user
int j;          //used to read input in a loop with getchar
int i;          //for-loop value
int len;            //used to calculate lengths different variables
int f;          //flag for the setup stage
int q;    //used to read input in a loop with getchar
q=0;    //reset the index reader
char in;    //to read characters
printf("Please enter the message you wish to send:\n");

************ Dies ist mein Code, um die Eingabenachricht zu lesen: ****************

//this loop reads the input from the user since C does not 
//provide a safe function to read strings with white spaces

while (in != '?'){   
in=getchar();
if(in != '?')    //dont include the delim character in the string
         msg[q++]=in;
}
msg[q]='\0';    //truncate the string by the null character

************ dann habe ich den Code (zitiert und referenziert) für die Verschlüsselung verwendet

Natürlich habe ich es als Nachricht geändert

for(i=0; i<strlen(msg); i++)    //copy the input message to plain
    plain[i] = msg[i];

//set up the shared key of the BF encryption

BF_set_key(&s_key, strlen(ekey_buf), ekey_buf);    

while(1){
    for(i=0; i<8; i++)    //reinitiate the block of 8 characters each time

        block[i] = 0;
    strncpy(block, plain+offset, 8);
    BF_cbc_encrypt(plain+offset, cipher, 8, &s_key, IV, BF_ENCRYPT);   
    for(i=0; i<strlen(cipher); i++){
    printf("%02x", (unsigned char) cipher[i]);
}
if( strlen(plain+offset)>8 ){    //if there is still more characters
     offset += 8;         //process the next block of 8 characters
} else
       break;       
}
//the cipher is correctly printed

************ dann habe ich den Code (zitiert und referenziert) für die Entschlüsselung verwendet

Hier habe ich den Teil ausgeschlossen, in dem es die Chiffre token und das einfache Zeichenarray für die Entschlüsselung erstellte. Strlen (Chiffre)

//set up the shared key of the BF encryption

BF_set_key(&s_key, strlen(dkey_buf), dkey_buf);        
BF_cbc_encrypt(cipher, plain, strlen(cipher), &s_key, IV, BF_DECRYPT);  

printf("plain after decryption: %s\n", plain);
//HERE IS THE PROBLEM: I get unreadable characters as output of this line

Jede Hilfe wird geschätzt. Entschuldigung für die Unannehmlichkeiten und vielen Dank im Voraus.

War es hilfreich?

Lösung

Ich habe eine Ahnung, es ist eine schmutzige IV, aber es ist nur eine Vermutung.

for(i=0; i<8; i++) ivec[i] = 'i';
BF_cbc_encrypt(inputz, outputz, strlen(inputz), &key, ivec, BF_ENCRYPT);

// won't decrypt right:
BF_cbc_encrypt(inputz, outputz, strlen(inputz), &key, ivec, BF_DECRYPT);
// without resetting the ivec to all 'i's, the decryption will fail.

// This would work though:

for(i=0; i<8; i++) ivec[i] = 'i';
BF_cbc_encrypt(inputz, outputz, strlen(inputz), &key, ivec, BF_ENCRYPT);

for(i=0; i<8; i++) ivec[i] = 'i';
BF_cbc_encrypt(inputz, outputz, strlen(inputz), &key, ivec, BF_DECRYPT);

Meine Vermutung ist nur korrekt, wenn jeder Block nach dem ersten entschlüsselt ist.

Ein weiteres großes Problem mit Strlen (InputZ) ist, dass Ihr Entschlüsselter letztendlich fehlschlägt, wenn der Strlen () nicht genau an einer 8Byte -Grenze fällt. Ich habe das Problem eher vollständig als GIST auf Github.

Andere Tipps

Überprüfen Sie Ihre Codierung.

Sie müssen null enden plain dh so etwas wie plain[ strlen(dkey_buf) ] = 0 wird gebraucht.

Gibt es keine Patentbeschränkungen bei der Verwendung/Verteilung von Programmen, die den IBE -Algorithmus nutzen?

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top