Solved

OpenSSL with C++, 3DES Decrypt

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

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 63

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Encryption for Business Encryption (https://en.wikipedia.org/wiki/Encryption) ensures the safety of our data when sending emails. In most cases, to read an encrypted email you must enter a secret key that will enable you to decrypt the email. T…
There are many Password Managers (PM) out there to choose from. PM's can help with your password habits and routines, but they should not be a crutch you rely on too heavily. I also have an article for company/enterprise PM's.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

733 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