login about faq

Hello ,

I've already sent email to support, but I post it here, too, for sharing Q&A.

I've just tried Crypt product.

I have to create code to decrypt 3DES string.

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

echo -en "xcax99x19x61xd1x21x4f......." | openssl des3 -d -K e3c254b6ec976b4638f216c83de61504166d7.... -iv 4eed0d2f1c....

I have to create code those function in C++Builder and your product.

Now my code is..

const char * ivHex; ivHex = "4eed0d2f1c48...."; crypt.SetEncodedIV(ivHex,"hex");

const char * keyHex; keyHex = "e3c254b6ec976b4638f216c83de61504166d7070ae97...."; crypt.SetEncodedKey(keyHex,"hex");

char encrypted[] = {0xca,0x99,0x19,0x61,0xd1,0x21,0x4f,0x77,0x3e,0x0d,0xd3,0xcc,0x07,0x9f,0x..,0x..}; Is that correct ? And I don't know how to decrypt encrypted string.

Please advice.

Nobuo Miwa

asked Dec 28 '12 at 10:30

NobMiwa's gravatar image

NobMiwa
1112


12next page »

Please provide the full data so that I can actually run the openssl command to see the results.

link

answered Dec 28 '12 at 10:53

chilkat's gravatar image

chilkat ♦♦
11.8k316358421

Thanks.

OpenSSL command line is followings..

echo -en "xcax99x19x61xd1x21x4fx77x3ex0dxd3xccx07x9fx56x24" | openssl des3 -d -K e3c254b6ec976b4638f216c83de61504166d7070ae97bfb6 -iv 4eed0d2f1c48e0f1

Answer is "berobero"

Regards

link

answered Dec 28 '12 at 10:57

NobMiwa's gravatar image

NobMiwa
1112

When I try that exact openssl command, I get an error:

echo -en "xcax99x19x61xd1x21x4fx77x3ex0dxd3xccx07x9fx56x24" | openssl des3 -d -K e3c254b6ec976b4638f216c83de61504166d7070ae97bfb6 -iv 4eed0d2f1c48e0f1
bad decrypt
10384:error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt:evp_enc.c:461:
��<L��?՝��5.���YM�ǝ�u��D@!g�r��chilkat@ubuntu:~/test/openssl$ 

(Dec 28 '12 at 11:40) chilkat ♦♦

Thank you for reply.

You need (back slash) with each byte of echo string

"(back slash)xca(back slash)x99(back slash)x19(back slash)x61(back slash)xd1(back slash)x21(back slash)x4f(back slash)x77(back slash)x3e(back slash)x0d(back slash)xd3(back slash)xcc(back slash)x07(back slash)x9f(back slash)x56(back slash)x24"

Somehow back slash has gone with my last post. (back slash)xca means a binary character like 0xca.

Regards, Nobuo Miwa

link

answered Jan 07 '13 at 17:16

NobMiwa's gravatar image

NobMiwa
1112

Here's sample code that works:

void des3_decrypt(void)
    {
    CkCrypt2 crypt;

crypt.UnlockComponent("test");

crypt.put_CryptAlgorithm("3des");
crypt.put_KeyLength(192);

const char * ivHex; 
ivHex = "4eed0d2f1c48e0f1"; 
crypt.SetEncodedIV(ivHex,"hex");

const char * keyHex; 
keyHex = "e3c254b6ec976b4638f216c83de61504166d7070ae97bfb6";

crypt.SetEncodedKey(keyHex,"hex");

CkByteData bData;
bData.appendEncoded("ca991961d1214f773e0dd3cc079f5624","hex");

printf("%s\n",crypt.decryptString(bData));
}
link

answered Jan 07 '13 at 22:06

chilkat's gravatar image

chilkat ♦♦
11.8k316358421

edited Jan 07 '13 at 22:06

Great thanks !

It worked !

link

answered Jan 08 '13 at 10:25

NobMiwa's gravatar image

NobMiwa
1112

I'm sorry.. Another decryption case..

I put followings in your code..

ivHex = "f80150b898ddc36f";

keyHex = "f59323a693069c4aeecc65cc89322504f698fd00c2c6db3c";

bData.appendEncoded("174b2e13d63703efbfcb4f060ef76f037ca9aa2789613696b30413cb77fb6cdc47352b3e7f62b7c0c278c6348af4ff6cf7e598bde24e92b508b08c5d34ce1d498337c741c1ff961f2c8904fb9c8a145a2e5c156ff991826284b209491fb2dd86","hex");

Then I got 60 bytes length.

But with openssl command followings..

echo -en "\x17\x4b\x2e\x13\xd6\x37\x03\xef\xbf\xcb\x4f\x06\x0e\xf7\x6f\x03\x7c\xa9\xaa\x27\x89\x61\x36\x96\xb3\x04\x13\xcb\x77\xfb\x6c\xdc\x47\x35\x2b\x3e\x7f\x62\xb7\xc0\xc2\x78\xc6\x34\x8a\xf4\xff\x6c\xf7\xe5\x98\xbd\xe2\x4e\x92\xb5\x08\xb0\x8c\x5d\x34\xce\x1d\x49\x83\x37\xc7\x41\xc1\xff\x96\x1f\x2c\x89\x04\xfb\x9c\x8a\x14\x5a\x2e\x5c\x15\x6f\xf9\x91\x82\x62\x84\xb2\x09\x49\x1f\xb2\xdd\x86" | openssl des3 -d -K f59323a693069c4aeecc65cc89322504f698fd00c2c6db3c -iv f80150b898ddc36f > tmp.dat

I got 91 bytes from tmp.dat

Each result byte were little differences from openssl's one.

Please advice to get 91 bytes from your code.

link

answered Jan 08 '13 at 23:17

NobMiwa's gravatar image

NobMiwa
1112

edited Jan 08 '13 at 23:21

Hello,

How about above case ?

Please advice, Regards, Nobuo Miwa

link

answered Jan 11 '13 at 11:31

NobMiwa's gravatar image

NobMiwa
1112

The KeyLength for your new case is 384, not 192. You need to multiply the length of your key string by 8 to get the appropriate key length.

link

answered Jan 11 '13 at 11:59

jpbro's gravatar image

jpbro ♦
1.1k2618

Thank you for advice.

I set to key length like this..

crypt.put_KeyLength(384);

But I still got 60 bytes of decrypted string length.

Please advice, Nobuo MMiwa

link

answered Jan 11 '13 at 20:34

NobMiwa's gravatar image

NobMiwa
1112

Not sure - I got 91 bytes, but I'm using VB6 so I don't know if that will be any help to you. Can you post your entire code that returns 60 bytes, and I'll see if I can notice any problems?

(Jan 11 '13 at 20:40) jpbro ♦

Here's my VB6 code that is returning 91 characters, it might be of some help:

Sub Test5()
   Dim lo_Crypt As New CHILKATCRYPT2Lib.ChilkatCrypt2

   With lo_Crypt
        .UnlockComponent "UNLOCKCODE"
        .EncodingMode = "hex"
        .CryptAlgorithm = "3des"
        .KeyLength = 384
        .SetEncodedIV "f80150b898ddc36f", "hex"
        .SetEncodedKey "f59323a693069c4aeecc65cc89322504f698fd00c2c6db3c", "hex"

        Debug.Print .DecryptStringENC("174b2e13d63703efbfcb4f060ef76f037ca9aa2789613696b30413cb77fb6cdc47352b3e7f62b7c0c278c6348af4ff6cf7e598bde24e92b508b08c5d34ce1d498337c741c1ff961f2c8904fb9c8a145a2e5c156ff991826284b209491fb2dd86")
    End With
End Sub
link

answered Jan 11 '13 at 21:01

jpbro's gravatar image

jpbro ♦
1.1k2618

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×26
×6

Asked: Dec 28 '12 at 10:30

Seen: 2,037 times

Last updated: Jan 12 '13 at 14:13

powered by OSQA