?
Solved

OpenSSL with C++, 3DES Decrypt

Posted on 2012-12-28
3
Medium Priority
?
2,764 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 64

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 64

Accepted Solution

by:
btan earned 1500 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

Need protection from advanced malware attacks?

Look no further than WatchGuard's Total Security Suite, providing defense in depth against today's most headlining attacks like Petya 2.0 and WannaCry. Keep your organization out of the news with protection from known and unknown threats.

Question has a verified solution.

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

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Businesses who process credit card payments have to adhere to PCI Compliance standards. Here’s why that’s important.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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…
Suggested Courses
Course of the Month9 days, 11 hours left to enroll

762 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