Note that there are some explanatory texts on larger screens.

plurals
  1. PO3DES result in Java produces different result from 3DES iOS version
    primarykey
    data
    text
    <p>I really really.... really need help...........</p> <p><strong>-UPDATED-</strong></p> <p>I need help because my java function gives me a different result compared with the iOS 3DES function. I posted the code from both ios and java; and results when specified plaintext is "tutor.1" and MD5 key is "spO13+QLZCRAe93pIXMXLg==" (MD5, clearly, is the same for both).</p> <p><strong>JAVA 3DES</strong> (short and simple)</p> <pre><code>public static String encrypt(String plaintext, String enctoken){ if(enctoken == null) enctoken = "sfdjf48mdfdf3054"; String encrypted = null; byte[] plaintextByte = EncodingUtils.getBytes(plaintext,"UTF-8"); byte[] hash = Connessione.md5(enctoken); Log.i("ENCRYPT", "MD5: "+Base64.encodeToString(hash, 0)); try { Cipher cipher = Cipher.getInstance("DESEDE/ECB/PKCS5Padding"); SecretKeySpec myKey = new SecretKeySpec(hash,"DESede"); cipher.init(Cipher.ENCRYPT_MODE, myKey); try { byte[] encryptedPlainText = cipher.doFinal(plaintextByte); encrypted = Base64.encodeToString(encryptedPlainText, 0); Log.i("ENCRYPT", "Pwd encrypted: "+encrypted); return encrypted; } catch (IllegalBlockSizeException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (BadPaddingException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch (NoSuchAlgorithmException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NoSuchPaddingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InvalidKeyException e) { // TODO Auto-generated catch block e.printStackTrace(); } return ""; } </code></pre> <p>result: <em>R4mXAaHcFxM=</em></p> <p><strong>IOS 3DES - UPDATED AGAIN</strong></p> <pre><code>// key value in parameters is MD5 value! It is the same for both version + (NSString *) encrypt:(NSString *) dataToEncrypt withKey:(NSString*) key{ NSData *data = [dataToEncrypt dataUsingEncoding:NSUTF8StringEncoding]; NSData *mData = [key dataUsingEncoding:NSUTF8StringEncoding]; CCCryptorStatus ccStatus = kCCSuccess; // Begin to calculate bytesNeeded.... size_t bytesNeeded = 0; ccStatus = CCCrypt(kCCEncrypt, kCCAlgorithm3DES, kCCOptionECBMode | kCCOptionPKCS7Padding, [mData bytes], [mData length], nil, [data bytes], [data length], NULL, 0, &amp;bytesNeeded); if(kCCBufferTooSmall != ccStatus){ NSLog(@"Here it must return BUFFER TOO SMALL !!"); return nil; } // .....End // Now i do the real Crypting char* cypherBytes = malloc(bytesNeeded); size_t bufferLength = bytesNeeded; if(NULL == cypherBytes) NSLog(@"cypherBytes NULL"); ccStatus = CCCrypt(kCCEncrypt, kCCAlgorithm3DES, kCCOptionECBMode | kCCOptionPKCS7Padding, [mData bytes], [mData length], nil, [data bytes], [data length], cypherBytes, bufferLength, &amp;bytesNeeded); if(kCCSuccess != ccStatus){ NSLog(@"kCCSuccess NO!"); return nil; } return [Base64 encode:[NSData dataWithBytes:cypherBytes length:bufferLength]]; </code></pre> <p>}</p> <p>result: <em>YBAva5J2khY=</em></p> <p>I need iOS version returns same result as the Java version.</p> <p>I found the Base64 class here: <a href="http://www.imthi.com/blog/programming/iphone-sdk-base64-encode-decode.php" rel="nofollow">http://www.imthi.com/blog/programming/iphone-sdk-base64-encode-decode.php</a></p> <p>What i'm doing wrong ?</p> <p>Thx for your help and time</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload