Hi,
i need a PHP complement to the Java Cipher, as Sample:
IV:
byte[] buff = new byte[str.length - 8];
byte[] iv = new byte[16];
for (int i = 0; i <= 7; i++)
iv[i] = str[i];
for (int i = 8; i <= 15; i++)
iv[i] = (byte) 0;
for (int i = 0; i <= str.length - 9; i++)
buff[i] = str[i + 8];
Cipher:
Cipher cipher = Cipher.getInstance("AES/CTR/NoPadding");
cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(key, "AES"),
new IvParameterSpec(iv));
byte[] decrypted = cipher.doFinal(buff);
I test in special:
Text: blah
Key: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
IV(Byte): 188,183,52,182,33,1,0,0
Cipher-Text(Byte): 188,183,52,182,33,1,0,0,248,122,172,154
Hi,
i need a PHP complement to the Java Cipher, as Sample:
IV:
byte[] buff = new byte[str.length - 8];
byte[] iv = new byte[16];
for (int i = 0; i <= 7; i++)
iv[i] = str[i];
for (int i = 8; i <= 15; i++)
iv[i] = (byte) 0;
for (int i = 0; i <= str.length - 9; i++)
buff[i] = str[i + 8];
Cipher:
Cipher cipher = Cipher.getInstance("AES/CTR/NoPadding");
cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(key, "AES"),
new IvParameterSpec(iv));
byte[] decrypted = cipher.doFinal(buff);
I test in special:
Text: blah
Key: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
IV(Byte): 188,183,52,182,33,1,0,0
Cipher-Text(Byte): 188,183,52,182,33,1,0,0,248,122,172,154
with my PHP-script:
<?php
$key = chr(255).chr(255).chr(255).chr(255).chr(255).chr(255).chr(255).chr(255);
$key .= chr(255).chr(255).chr(255).chr(255).chr(255).chr(255).chr(255).chr(255);
$dataa = explode(",", "188,183,52,182,33,1,0,0,248,122,172,154");
for($i=0 ; $i<8 ; $i++) $iv .= chr($dataa[$i]);
for($i=0 ; $i<8 ; $i++) $iv .= chr(0);
for($i=8 ; $i<count($dataa) ; $i++) $data .= chr($dataa[$i]);
echo "Key: $key | IV: $iv | Data: $data<br>";
$td = mcrypt_module_open("rijndael-128", "", "ctr", $iv);
mcrypt_generic_init($td, $key, $iv);
$encrypted_data = mcrypt_generic($td, $data);
echo bin2hex($encrypted_data)." | ".$encrypted_data;
mcrypt_generic_deinit($td);
mcrypt_module_close($td);
?>
But i dont get the same result :(
What do i wrong!?