Use K iv parameters to pass HEX formatted key,iv
Francesco Petruzzi francesco.petru...@innovery.it -------- The information contained in this electronic message and any attachments (the "Message") is intended for one or more specific individuals or entities, and may be confidential, proprietary, privileged or otherwise protected by law. If you are not the intended recipient, please notify the sender immediately, delete this Message and do not disclose, distribute, or copy it to any third party or otherwise use this Message. Electronic messages are not secure or error free and can contain viruses or may be delayed, and the sender is not liable for any of these occurrences. The sender reserves the right to monitor, record and retain electronic messages. -------- Le informazioni contenute in questo messaggio e gli eventuali allegati (il "Messaggio") si intendono inviate a uno o piú specifici destinatari. Il contenuto del Messaggio puó essere confidenziale, riservato e comunque protetto dalla legge applicabile. Se non siete i destinatari del Messaggio, siete pregati di informare immediatamente il mittente, cancellare questo Messaggio, non rivelarlo, non distribuirlo ne' inoltrarlo a terzi, non copiarlo né farne alcun uso. I messaggi di posta elettronica non sono sicuri e sono soggetti ad alterazioni, possono essere trasmettitori di Virus informatici o soggetti a ritardi nella distribuzione. Il mittente del Messaggio non puó essere in alcun modo considerato responsabile per queste evenienze. Il mittente si riserva il diritto di archiviare, ritenere e controllare i messaggi di posta elettronica. _____ Da: owner-openssl-us...@openssl.org [mailto:owner-openssl-us...@openssl.org] Per conto di ~ Kunal Sharma ~ Inviato: martedì 25 maggio 2010 14.30 A: openssl-users@openssl.org Oggetto: Error - AES-256 CBC encrypting using EVP routines and decrypting using command line Friends, I'm trying to verify that my encryption and decryption routines work ok. One way I do it is to encrypt the data and save it to a file. The I feed the encrypted file to my decryption routine and write the decrypted data to another file. I compare the original data and the contents of the decrypted file and they are same. So the routines work fine in tandem. Another method I want to use it to encrypt the data and save it to a file. Then I feed the encrypted file to Openssl command line to decrypt. I get my encrypted data in the file rgconf_encrypted. Then I run the following command: openssl enc -d -aes-256-cbc -in rgconf_encrypted I enter the decryption password "As different as chalk and cheese" which I used to encrypt the data. But I get the error "bad magic number". Am I missing something here ? I need to be able to use a simple phrase as my encryption password so I can decrypt it on command line as well. Please provide any pointers on what could be wrong here. Below is the code for my encryption routine. Thanks, Kunal ++++++++++++++++++++++++++++++++++++++++++ int encrypt(void) { EVP_CIPHER_CTX ctx; unsigned char ibuf[1024],obuf[1024]; int rfd, wfd,ilen,olen,tlen; unsigned char key32[] = "As different as chalk and cheese"; unsigned char iv[] = "As dark as pitch"; EVP_CIPHER_CTX_init(&ctx); if(!EVP_CipherInit_ex(&ctx, EVP_aes_256_cbc(),NULL,key32, iv,AES_ENCRYPT) ) { console_printf("Couldnt initialize cipher\n"); return 1; } /* read the original contents that are stored in file /etc/rgconf */ if((rfd = open("/etc/rgconf",O_RDONLY) ) == -1) { console_printf("Couldnt open input file\n"); return 1; } /* open a file /et.rgconf_encrypted to store encrypted data */ if((wfd = creat("/etc/rgconf_encrypted",0644) ) == -1) { console_printf("Couldn't open output file for writing\n"); return 1; } while((ilen = read(rfd,ibuf,1024) ) > 0) { if(EVP_CipherUpdate(&ctx,obuf,&olen,ibuf,ilen)){ write(wfd,obuf,olen); } else { console_printf("Encryption error\n"); return 1; } } if(!EVP_CipherFinal_ex(&ctx,obuf+olen,&tlen)) { console_printf("Trouble with padding the last block\n"); return 1; } write(wfd,obuf+olen,tlen); EVP_CIPHER_CTX_cleanup(&ctx); close(rfd); close(wfd); console_printf("AES 256 CBC encryption complete\n"); return 0; } ++++++++++++++++++++++++++++++++++++++++++