Solved

OpenSSL with C++, 3DES Decrypt

Posted on 2012-12-28
3
2,386 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 61

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 61

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Article by: btan
Provide an easy one stop to quickly get the relevant information on common asked question on Ransomware in Expert Exchange.
As a financial services provider, your business is impacted by two of the strictest federal regulations on record: the Sarbanes-Oxley Act and the Gramm-Leach-Bliley Act. Correctly implementing faxing into your organization to provide secure, real-ti…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
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.

760 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now