javaaes加密与PHP

javaaes加密与PHP,java,php,encryption,Java,Php,Encryption,我搜索了所有与此相关的帖子,但找不到任何实际可行的解决方案 我需要一个PHP的等价物 我用JAVA编写了以下代码: String m_sSendStringEncrypt = ""; try{ String m_sReqSendString = "StringToBeEncrypted"; String m_sSalt = "test"; // not to change m_sSendStringEncrypt = encrypt(m_sReqSendString, m

我搜索了所有与此相关的帖子,但找不到任何实际可行的解决方案

我需要一个PHP的等价物

我用JAVA编写了以下代码:

String m_sSendStringEncrypt = "";
try{
    String m_sReqSendString = "StringToBeEncrypted";
    String m_sSalt = "test"; // not to change
    m_sSendStringEncrypt = encrypt(m_sReqSendString, m_sSalt);
}catch(Exception e){
    System.out.println("Exception:: " + e);
}


private static final String ALGORITHM = "AES";
private static final int ITERATIONS = 2;
private static final byte[] keyValue = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05,    0x06, 0x07, 0x08, 0x09,0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }; // not to change

public static String encrypt(String value, String salt) throws Exception {
     Key key = generateKey();
     Cipher c = Cipher.getInstance(ALGORITHM);  
     c.init(Cipher.ENCRYPT_MODE, key);

     String valueToEnc = null;
     String eValue = value;
     for (int i = 0; i < ITERATIONS; i++) {
          valueToEnc = salt + eValue;
          byte[] encValue = c.doFinal(valueToEnc.getBytes());
          eValue = new BASE64Encoder().encode(encValue);
     }
     return eValue;
}
private static Key generateKey() throws Exception {
     Key key = new SecretKeySpec(keyValue, ALGORITHM);
     return key;
}
String m_sSendStringEncrypt=”“;
试一试{
字符串m_sReqSendString=“StringToBeEncrypted”;
字符串m_sSalt=“test”//不更改
m_sSendStringEncrypt=加密(m_sReqSendString,m_sSalt);
}捕获(例外e){
System.out.println(“异常::”+e);
}
私有静态最终字符串算法=“AES”;
私有静态最终整数迭代=2;
私有静态最终字节[]keyValue=新字节[]{0x00、0x01、0x02、0x03、0x04、0x05、0x06、0x07、0x08、0x09、0x0a、0x0b、0x0c、0x0d、0x0e、0x0f};//不变
公共静态字符串加密(字符串值、字符串盐)引发异常{
Key=generateKey();
Cipher c=Cipher.getInstance(算法);
c、 init(Cipher.ENCRYPT_模式,密钥);
字符串valueToEnc=null;
字符串eValue=值;
对于(int i=0;i
这可能会有所帮助。@Newbi3花了大约10秒。他提出的问题是谷歌的第一个条目。你看起来显然没那么努力。