Solved

OpenSSL with C++, 3DES Decrypt

Posted on 2012-12-28
3
2,474 Views
Last Modified: 2013-01-08
Hello Experts,

I have to create code to decrypt using OpenSSL 3DES in C++.

I decrypted my encrypted string with OpenSSL command line like followings,

echo -en "\xca\x99\x19\x61\xd1\x21\x4f......." |
openssl des3 -d
-K  e3c254b6ec976b4638f216c83de61504166d7.... -iv 4eed0d2f1c....

I have to create code those function in C++(DES_ncbc_encrypt()..etc).
I've already installed OpenSSL in my environment.

Windows 7 32bit, C++Builder

Please advice.
0
Comment
Question by:NobMiwa
  • 2
3 Comments
 
LVL 62

Expert Comment

by:btan
ID: 38728842
0
 

Author Comment

by:NobMiwa
ID: 38729179
Thank you for information.

I coded followings..

	unsigned char key[] = {0xe3,0xc2,0x54,0xb6,0xec,0x97,0x6b,0x46,0x38,0xf2,0x16,0xc8,0x3d,0xe6,0x15,0x04,0x16,0x6d,0x70,0x70,0xae,0x97,0xbf,0xb6};

	unsigned char iv[]  = {0x4e,0xed,0x0d,0x2f,0x1c,0x48,0xe0,0xf1};
	unsigned char encrypted[] = {0xca,0x99,0x19,0x61,0xd1,0x21,0x4f,0x77,0x3e,0x0d,0xd3,0xcc,0x07,0x9f,0x56,0x24};

	const EVP_CIPHER* cipherType = EVP_des_ede3_ecb();
	EVP_CIPHER_CTX ctx;
	EVP_CIPHER_CTX_init(&ctx);
	int rt = EVP_DecryptInit(&ctx, (const EVP_CIPHER*)cipherType, (const unsigned char*)key, (const unsigned char*)iv);

	int out_len;
	char ciphertext[2048] = {0};
	memset(ciphertext, 0x00, sizeof(ciphertext));

	rt = EVP_DecryptUpdate(&ctx, (unsigned char*)ciphertext, &out_len, (const unsigned char*)encrypted, 16);
	rt = EVP_DecryptFinal(&ctx, (unsigned char*)ciphertext, &out_len);

	rt = EVP_CIPHER_CTX_cleanup(&ctx);

Open in new window


The answer must be "berobero", but I got 8 letters and was not the answer.

Please advice, if you have any idea..
0
 
LVL 62

Accepted Solution

by:
btan earned 500 total points
ID: 38729331
Was thinking an6thing to do with padding or the parameter to decrypt function

http://www.openssl.org/docs/crypto/EVP_EncryptInit.html

.

EVP_DecryptInit_ex(),EVP_DecryptUpdate() andEVP_DecryptFinal_ex() are the corresponding decryption operations.EVP_DecryptFinal() will return an error code if padding is enabled and the final block is not correctly formatted. The parameters and restrictions are identical to the encryption operations except that if padding is enabled the decrypted data buffer out passed toEVP_DecryptUpdate() should have sufficient room for (inl + cipher_block_size) bytes unless the cipher block size is 1 in which case inl bytes is sufficient.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Provide an easy one stop to quickly get the relevant information on common asked question on Ransomware in Expert Exchange.
SSL stands for “Secure Sockets Layer” and an SSL certificate is a critical component to keeping your website safe, secured, and compliant. Any ecommerce website must have an SSL certificate to ensure the safe handling of sensitive information like…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question