problema con encrypt
Matteo Vidovich <[email protected]>
| Newsgroups | gmane.comp.cms.cold-fusion.devel.italian |
|---|---|
| Message-ID | <[email protected]> |
Ciao a tutti,
un nostro cliente criÚta delle stringhe con algoritmo Triple DES in PHP e in Java utilizzando sempre lo stesso risultato. Io avrei bisogno di ottenerlo criptando in CF ma non ci riesco proprio.
Il codice php che utilizza Ú:
$cryptoKey = "12345678901234567890123456789012";
$cryptoKeyHex = unpack('H*', $cryptoKey); // Da usare solo come test con chiave esadecimale
$input = $credentials['user'] . $result->name . $cryptoKey; // name arriva dalla tabella, user dalla request
$testcrypt = mcrypt_ecb(MCRYPT_3DES, $cryptoKey, $input, MCRYPT_ENCRYPT); // Risultato binario non stampabile
$testcrypt0 = mcrypt_ecb(MCRYPT_3DES, $cryptoKeyHex[1], $input, MCRYPT_ENCRYPT);
$testcrypt64 = base64_encode($testcrypt); // Risultato con encoding base64
$testcrypt640 = base64_encode($testcrypt0);
$testcryptHex = unpack("H*", $testcrypt); // Array il cui elemento [1] Ú la codifica esadecimale da confrontare con la chiave che arriva
$testcryptHex0 = unpack("H*", $testcrypt0);
mentre la classe Java Ú:
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESedeKeySpec;
import org.apache.commons.codec.binary.Hex;
public class TripleDESEncryptionTest {
private static final String PLAIN_TEXT = "myString";
private static final String SHARED_KEY = "12345678901234567890123456789012";
public static void main(String[] args) throws Exception {
String algorithm = "DESede";
String transformation = "DESede/ECB/PKCS5Padding";
char[] charValue = SHARED_KEY.toCharArray();
byte[] keyValue = new byte[charValue.length];
for (int i = 0; i < charValue.length; i++)
{
keyValue[i] = (byte)charValue[i];
}
DESedeKeySpec keySpec = new DESedeKeySpec(keyValue);
SecretKey key = SecretKeyFactory.getInstance(algorithm).generateSecret(keySpec);
Cipher encrypter = Cipher.getInstance(transformation);
encrypter.init(Cipher.ENCRYPT_MODE, key);
byte[] input = PLAIN_TEXT.getBytes("UTF-8");
byte[] encrypted = encrypter.doFinal(input);
char[] enc = Hex.encodeHex(encrypted);
String s = String.valueOf(enc);
System.out.println(s);
}
}
Oltre al semplice uso di encrypt() ho fatto diversi tentativi ma non sono mai riuscito ad ottenere il risultato del cliente.
La versione di CF Ú la 8 standard.
Qualche suggerimento?
Grazie in anticipo
--
Matteo
------------------------------------