<xsl:template match="/">
<feed>
<xsl:for-each select="web-export/run-date/pub-code/ad-type[descendant::FieldedDataSet/State[. = 'CT']]">
<xsl:copy-of select="."/>
</xsl:for-each>
</feed>
</xsl:template>
Java输出:
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import org.apache.commons.codec.binary.Base64;
class AES256JavaPhp{
public static void main(String[] args) throws Exception {
Base64 base64 = new Base64();
Cipher ciper = Cipher.getInstance("AES/CBC/PKCS5Padding");
SecretKeySpec key = new
SecretKeySpec("PasswordPassword".getBytes("UTF-8"),"AES");
IvParameterSpec iv = new IvParameterSpec
("dynamic@dynamic@".getBytes("UTF-8"),0,ciper.getBlockSize());
//Encrypt
ciper.init(Cipher.ENCRYPT_MODE, key,iv);
byte[] encryptedCiperBytes = base64.encode
((ciper.doFinal("Hello".getBytes())));
System.out.println("Ciper : "+new String(encryptedCiperBytes));
//Decrypt
ciper.init(Cipher.DECRYPT_MODE, key,iv);
byte[] text = ciper.doFinal(base64.decode(encryptedCiperBytes));
System.out.println("Decrypt text : "+new String(text));
}
}
Ciper : KpgzpzCRU7mTKZePpPlEvA==
Decrypt text : Hello
PHP输出:
<?php>
$cipherText = encrypt("Hello", 'aes-256-cbc');
exit();
function encrypt($data, $algo)
{
$key = 'PasswordPassword';
//$iv = random_bytes(openssl_cipher_iv_length($algo));
$iv = 'dynamic@dynamic@';
$cipherText = openssl_encrypt(
$data,
$algo,
$key,
OPENSSL_RAW_DATA,
$iv
);
$cipherText = base64_encode($cipherText);
printData("Ciper Text : $cipherText");
$cipherText = base64_decode($cipherText);
$plaintext = openssl_decrypt(
$cipherText,
$algo,
$key,
OPENSSL_RAW_DATA,
$iv
);
printData("Plain Text after decryption : $plaintext");
}
function printData($obj)
{
print_r($obj);
}
?>
生成的密码是不同的,即使它们使用相同的密钥和IV。这怎么可能?
答案 0 :(得分:0)
您的密钥长度只有128位(16字节),但您在PHP中请求AES-256。这将导致填充的AES密钥为256位(32字节)。您必须要求AES-128才能使用。这就是OpenSSL扩展在PHP中的工作方式。
理想情况下,键应该看起来像随机噪音,以防止暴力攻击。你当前的钥匙不是那个。这是非常可预测的。您应该生成一些随机密钥并将其以编码形式添加到您的代码中,如Base64。然后你可以在使用前解码它。