Solved

OpenSSL with C++, 3DES Decrypt

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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.
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…
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…

863 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

26 Experts available now in Live!

Get 1:1 Help Now