سؤال

Can you help me please.

I have developed an iOS application. I tried to encrypt a string with the 3DES algorithm, but I found a different result from Java code. Key should be md5 and size 24 byte. My friend encrypted the plaintext with Java and he got an encrypted base64 string. but I get different results. :(

Where am I going wrong?

هل كانت مفيدة؟

المحلول

md5 outputs a 128 bit (16 byte) hash, while 3DES takes a 168 bit (21 byte) key. I would suspect that passing an md5 hash into your encryption and/or decryption algorithm is causing some padding to take place along the way.

It would be better to either use SHA256 (which outputs a 256 bit hash) and truncate the output to 168 bits, or use AES-256 instead of 3DES with the full 256 bit hash as the key. Even better than that would be to use a proper key derivation function like PBKDF2 to create a key from a string password.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top