...
Android

Android Java ASE加解密与PHP AES加解密

AES-128-ECB

PHP:

/**
 * AES 加解密
 */
class AES
{
    private static $key = ""; //16位key

    public static function encrypt($input, $key)
    {
        $data = openssl_encrypt($input, 'AES-128-ECB', $key, OPENSSL_RAW_DATA);
        $data = base64_encode($data);
        return $data;
    }

    public static function decrypt($sStr)
    {
        $decrypted = openssl_decrypt(base64_decode($sStr), 'AES-128-ECB', self::$key, OPENSSL_RAW_DATA);
        return $decrypted;
    }
}

JAVA:

import android.util.Base64;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import java.security.Key;

public class AES {
    private static final String AESTYPE = "AES/ECB/PKCS5Padding";
    private static final String KEY = ""; //16位key

    public static String AES_Encrypt(String plainText) {
        byte[] encrypt = null;
        try {
            Key key = generateKey(KEY);
            Cipher cipher = Cipher.getInstance(AESTYPE);
            cipher.init(Cipher.ENCRYPT_MODE, key);
            encrypt = cipher.doFinal(plainText.getBytes());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Base64.encodeToString(encrypt, 0);
    }

    public static String AES_Decrypt(String encryptData) {
        byte[] decrypt = null;
        try {
            Key key = generateKey(KEY);
            Cipher cipher = Cipher.getInstance(AESTYPE);
            cipher.init(Cipher.DECRYPT_MODE, key);
            decrypt = cipher.doFinal(Base64.decode(encryptData, 0));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new String(decrypt).trim();
    }

    private static Key generateKey(String key) throws Exception {
        try {
            SecretKeySpec keySpec = new SecretKeySpec(key.getBytes(), "AES");
            return keySpec;
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        }
    }
}
php文件缓存类,简单的文件缓存 Windows 10系统连接共享打印机报错0x00000709、0x0000007c、0x0000011b
biu biu biu
Ubuntu 搭建SVN服务器(SVN Server) android 备份system.img dd命令的使用 android 安卓 adb 禁止系统休眠 android 挂载可读写system分区 Read-only file system Linux命令大全(手册)