编辑代码

import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;
import javax.crypto.spec.PBEParameterSpec;
import java.security.spec.AlgorithmParameterSpec;
import java.security.spec.KeySpec;
import java.util.Base64;

public class PBEEncryptionExample {

    public static void main(String[] args) throws Exception {
        String textToEncrypt = "http://111.180.195.228:5147/api.php?act=user_logon&app=10000";
        String password = "your_password_here"; // 用作密钥的密码

        // 创建PBE密钥
        SecretKeyFactory factory = SecretKeyFactory.getInstance("PBEWithMD5AndDES");
        KeySpec keySpec = new PBEKeySpec(password.toCharArray());
        SecretKey secretKey = factory.generateSecret(keySpec);

        // 创建加密器
        Cipher cipher = Cipher.getInstance("PBEWithMD5AndDES");
        AlgorithmParameterSpec paramSpec = new PBEParameterSpec(new byte[]{1, 2, 3, 4, 5, 6, 7, 8}, 1000); // 这里的参数可以根据需要更改
        cipher.init(Cipher.ENCRYPT_MODE, secretKey, paramSpec);

        // 加密文本
        byte[] encrypted = cipher.doFinal(textToEncrypt.getBytes());

        // 将加密结果转换为Base64字符串
        String encryptedBase64 = Base64.getEncoder().encodeToString(encrypted);

        System.out.println("Encrypted text: " + encryptedBase64);
    }
}