A java aes encryption, if it is implemented with php, what should it be like, my environment is php8+

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>public static void main(String[] args) throws Exception {
String data = "4097c9863a1ee0b82d53e103cc6262e56bab259f5f3c01b0c3a3be1ddfd511ff";
String des_key = "cputest";
String decode_data = aes_decode(des_key,data);
System.out.println(decode_data);
}
private static Key GetAESKey(String key) throws Exception {
KeyGenerator kgen = KeyGenerator.getInstance("AES");
SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
random.setSeed(key.getBytes());
kgen.init(256, random);
SecretKey secretKey = kgen.generateKey();
byte[] enCodeFormat = secretKey.getEncoded();
SecretKeySpec secretKeySpec = new SecretKeySpec(enCodeFormat, "AES");
return secretKeySpec;
}
private static String aes_encode(String des_key, String data) throws Exception {
String[] args = new String[]{data};
Key key = GetAESKey(des_key);
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
cipher.init(1, key);
return byteArr2HexStr(cipher.doFinal(args[0].getBytes()));
}
private static String aes_decode(String des_key,String data) throws Exception {
String[] args = new String[]{data};
Key key = GetAESKey(des_key);
Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
cipher.init(2, key);
return new String(cipher.doFinal(hexStr2ByteArr(args[0])));
}
public static String byteArr2HexStr(byte[] value) throws Exception {
int i = value.length;
StringBuffer buf = new StringBuffer(i * 2);
for(int j = 0; j < i; ++j) {
int k;
for(k = value[j]; k < 0; k += 256) {
}
if (k < 16) {
buf.append("0");
}
buf.append(Integer.toString(k, 16));
}
return buf.toString();
}
public static byte[] hexStr2ByteArr(String value) throws Exception {
byte[] bs1 = value.getBytes();
int i = bs1.length;
byte[] bs2 = new byte[i / 2];
for(int j = 0; j < i; j += 2) {
String str = new String(bs1, j, 2);
bs2[j / 2] = (byte)Integer.parseInt(str, 16);
}
return bs2;
}
</code>
<code>public static void main(String[] args) throws Exception { String data = "4097c9863a1ee0b82d53e103cc6262e56bab259f5f3c01b0c3a3be1ddfd511ff"; String des_key = "cputest"; String decode_data = aes_decode(des_key,data); System.out.println(decode_data); } private static Key GetAESKey(String key) throws Exception { KeyGenerator kgen = KeyGenerator.getInstance("AES"); SecureRandom random = SecureRandom.getInstance("SHA1PRNG"); random.setSeed(key.getBytes()); kgen.init(256, random); SecretKey secretKey = kgen.generateKey(); byte[] enCodeFormat = secretKey.getEncoded(); SecretKeySpec secretKeySpec = new SecretKeySpec(enCodeFormat, "AES"); return secretKeySpec; } private static String aes_encode(String des_key, String data) throws Exception { String[] args = new String[]{data}; Key key = GetAESKey(des_key); Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); cipher.init(1, key); return byteArr2HexStr(cipher.doFinal(args[0].getBytes())); } private static String aes_decode(String des_key,String data) throws Exception { String[] args = new String[]{data}; Key key = GetAESKey(des_key); Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding"); cipher.init(2, key); return new String(cipher.doFinal(hexStr2ByteArr(args[0]))); } public static String byteArr2HexStr(byte[] value) throws Exception { int i = value.length; StringBuffer buf = new StringBuffer(i * 2); for(int j = 0; j < i; ++j) { int k; for(k = value[j]; k < 0; k += 256) { } if (k < 16) { buf.append("0"); } buf.append(Integer.toString(k, 16)); } return buf.toString(); } public static byte[] hexStr2ByteArr(String value) throws Exception { byte[] bs1 = value.getBytes(); int i = bs1.length; byte[] bs2 = new byte[i / 2]; for(int j = 0; j < i; j += 2) { String str = new String(bs1, j, 2); bs2[j / 2] = (byte)Integer.parseInt(str, 16); } return bs2; } </code>
public static void main(String[] args) throws Exception {
    String data = "4097c9863a1ee0b82d53e103cc6262e56bab259f5f3c01b0c3a3be1ddfd511ff";
    String des_key = "cputest";
    String decode_data = aes_decode(des_key,data);
    System.out.println(decode_data);
}

private static Key GetAESKey(String key) throws Exception {
    KeyGenerator kgen = KeyGenerator.getInstance("AES");
    SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
    random.setSeed(key.getBytes());
    kgen.init(256, random);
    SecretKey secretKey = kgen.generateKey();
    byte[] enCodeFormat = secretKey.getEncoded();
    SecretKeySpec secretKeySpec = new SecretKeySpec(enCodeFormat, "AES");
    return secretKeySpec;
}

private static String aes_encode(String des_key, String data) throws Exception {
    String[] args = new String[]{data};
    Key key = GetAESKey(des_key);
    Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
    cipher.init(1, key);
    return byteArr2HexStr(cipher.doFinal(args[0].getBytes()));
}


private static String aes_decode(String des_key,String data) throws Exception {
    String[] args = new String[]{data};
    Key key = GetAESKey(des_key);
    Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
    cipher.init(2, key);
    return new String(cipher.doFinal(hexStr2ByteArr(args[0])));
}

public static String byteArr2HexStr(byte[] value) throws Exception {
    int i = value.length;
    StringBuffer buf = new StringBuffer(i * 2);

    for(int j = 0; j < i; ++j) {
        int k;
        for(k = value[j]; k < 0; k += 256) {
        }

        if (k < 16) {
            buf.append("0");
        }

        buf.append(Integer.toString(k, 16));
    }

    return buf.toString();
}

public static byte[] hexStr2ByteArr(String value) throws Exception {
    byte[] bs1 = value.getBytes();
    int i = bs1.length;
    byte[] bs2 = new byte[i / 2];

    for(int j = 0; j < i; j += 2) {
        String str = new String(bs1, j, 2);
        bs2[j / 2] = (byte)Integer.parseInt(str, 16);
    }

    return bs2;
}

//This is a java code example, how to use php to achieve this equivalent decryption method, please ask me how to do so to write it. This is a java code example, how to use php to achieve this equivalent decryption method, please ask me how to do so to write it.That’s all the details I need

New contributor

xiaolan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật