### Execute Interactive JAR Encryption via CLI Source: https://context7.com/roseboy/classfinal/llms.txt Shows how to launch the ClassFinal interactive mode to encrypt Java archives. Users provide paths, package names, and passwords through a guided command-line prompt. ```bash # Start the interactive encryption process java -jar classfinal-fatjar-1.2.1.jar ``` -------------------------------- ### Decrypt classes and resources using JarDecryptor API Source: https://context7.com/roseboy/classfinal/llms.txt Provides examples for using the JarDecryptor singleton to decrypt class files, read encrypted files from JARs, and decrypt configuration streams at runtime. ```java import net.roseboy.classfinal.JarDecryptor; import java.io.File; import java.io.InputStream; public class DecryptExample { public static void main(String[] args) { JarDecryptor decryptor = JarDecryptor.getInstance(); String projectPath = "/path/to/encrypted-project.jar"; String className = "com.yourpackage.service.UserService"; char[] password = "MySecretPassword".toCharArray(); byte[] decryptedBytes = decryptor.doDecrypt(projectPath, className, password); if (decryptedBytes != null) { System.out.println("解密成功,字节码长度: " + decryptedBytes.length); } File jarFile = new File("/path/to/encrypted-project.jar"); byte[] encryptedData = JarDecryptor.readEncryptedFile(jarFile, className); char[] hiddenPassword = JarDecryptor.readPassFromJar(jarFile); InputStream encryptedStream = getEncryptedConfigStream(); InputStream decryptedStream = decryptor.decryptConfigFile("application.yml", encryptedStream, password); } private static InputStream getEncryptedConfigStream() { return null; } } ``` -------------------------------- ### Starting Encrypted JAR with ClassFinal Java Agent Source: https://context7.com/roseboy/classfinal/llms.txt Launches encrypted JAR files using the Java Agent mechanism for runtime decryption. This process occurs entirely in memory, leaving no decrypted files on disk. Various methods are provided for password input, including command-line arguments, console input, environment variables, and configuration files. ```bash # Method 1: Pass password via command-line argument java -javaagent:yourproject-encrypted.jar='-pwd 123456' -jar yourproject-encrypted.jar # Method 2: Enter password at console prompt (recommended) java -javaagent:yourproject-encrypted.jar -jar yourproject-encrypted.jar # Prompt after startup: Password: # Enter password and press Enter to start # Method 3: Pass password via environment variable export MY_APP_PASSWORD=123456 java -javaagent:yourproject-encrypted.jar='-pwdname MY_APP_PASSWORD' -jar yourproject-encrypted.jar # Method 4: Pass password via configuration file # Create classfinal.txt or yourproject-encrypted.classfinal.txt in the same directory as the JAR echo "123456" > classfinal.txt java -javaagent:yourproject-encrypted.jar -jar yourproject-encrypted.jar # Production environment recommendation: Disable Attach mechanism to prevent runtime debugging java -XX:+DisableAttachMechanism \ -javaagent:yourproject-encrypted.jar='-pwd 123456' \ -jar yourproject-encrypted.jar ``` -------------------------------- ### Tomcat Deployment of Encrypted WAR Packages with ClassFinal Source: https://context7.com/roseboy/classfinal/llms.txt Deploys encrypted WAR packages into a Tomcat container for execution. This involves configuring Tomcat's startup scripts (`catalina.sh` for Linux, `catalina.bat` for Windows) to include the ClassFinal Java Agent and the necessary decryption password. Environment variables can also be used for password management in production environments. ```bash # Linux environment - Edit tomcat/bin/catalina.sh # Add the following configuration at the beginning of the file CATALINA_OPTS="$CATALINA_OPTS -javaagent:/path/to/classfinal-fatjar-1.2.1.jar='-pwd 123456'" export CATALINA_OPTS # Windows environment - Edit tomcat/bin/catalina.bat set JAVA_OPTS="-javaagent:C:\path\to\classfinal-fatjar-1.2.1.jar='-pwd 123456'" # Pass password via environment variable (recommended for production) ``` -------------------------------- ### Encrypt JAR/WAR files using JarEncryptor API Source: https://context7.com/roseboy/classfinal/llms.txt Demonstrates how to programmatically encrypt JAR files using the JarEncryptor class. It covers setting target packages, including dependencies, excluding specific classes, and binding to machine codes. ```java import net.roseboy.classfinal.JarEncryptor; import java.util.Arrays; import java.util.List; public class EncryptExample { public static void main(String[] args) { String jarPath = "/path/to/yourproject.jar"; char[] password = "MySecretPassword".toCharArray(); JarEncryptor encryptor = new JarEncryptor(jarPath, password); List packages = Arrays.asList("com.yourpackage", "com.yourpackage.service", "com.yourpackage.dao"); encryptor.setPackages(packages); List includeJars = Arrays.asList("your-core.jar", "your-utils-*.jar"); encryptor.setIncludeJars(includeJars); List excludeClass = Arrays.asList("com.yourpackage.config.OpenConfig", "com.yourpackage.dto.*"); encryptor.setExcludeClass(excludeClass); List classPath = Arrays.asList("/path/to/tomcat/lib", "/path/to/other/libs"); encryptor.setClassPath(classPath); List cfgfiles = Arrays.asList("application.yml", "application-*.yml"); encryptor.setCfgfiles(cfgfiles); char[] machineCode = "XXXXXXXXXXXXXX".toCharArray(); encryptor.setCode(machineCode); String encryptedJarPath = encryptor.doEncryptJar(); Integer encryptedCount = encryptor.getEncryptFileCount(); System.out.println("加密完成: " + encryptedJarPath); System.out.println("加密文件数量: " + encryptedCount); } } ``` -------------------------------- ### Perform Cryptographic Operations with EncryptUtils Java API Source: https://context7.com/roseboy/classfinal/llms.txt Demonstrates how to use the EncryptUtils class for AES, RSA, MD5, and XOR operations. It covers both string and byte array processing, key pair generation, and random character generation. ```java import net.roseboy.classfinal.util.EncryptUtils; import java.util.Map; public class EncryptUtilsExample { public static void main(String[] args) throws Exception { String plainText = "Hello ClassFinal!"; char[] aesKey = "mySecretKey12345".toCharArray(); // AES Encryption/Decryption String encrypted = EncryptUtils.enAES(plainText, aesKey); String decrypted = EncryptUtils.deAES(encrypted, aesKey); // RSA Key Generation and Encryption Map keyPair = EncryptUtils.genKeyPair(); String publicKey = keyPair.get(0); String privateKey = keyPair.get(1); String rsaEncrypted = EncryptUtils.enRSA(plainText, publicKey); String rsaDecrypted = EncryptUtils.deRSA(rsaEncrypted, privateKey); // MD5 Hashing char[] md5Full = EncryptUtils.md5("myPassword".toCharArray()); // Random String Generation char[] randomChars = EncryptUtils.randChar(32); } } ``` -------------------------------- ### Launch Encrypted JAR Applications Source: https://github.com/roseboy/classfinal/blob/master/README.md Run the encrypted JAR by utilizing the built-in javaagent. The application decrypts class files in memory during runtime. ```sh # Option 1: Provide password in command java -javaagent:yourpaoject-encrypted.jar='-pwd 0000000' -jar yourpaoject-encrypted.jar # Option 2: Interactive password entry java -javaagent:yourpaoject-encrypted.jar -jar yourpaoject-encrypted.jar ``` -------------------------------- ### Configure Tomcat for Encrypted WAR Source: https://github.com/roseboy/classfinal/blob/master/README.md Configure the Tomcat server environment variables to include the javaagent required for decrypting WAR files at runtime. ```sh # Linux (catalina.sh) CATALINA_OPTS="$CATALINA_OPTS -javaagent:classfinal-fatjar.jar='-pwd 0000000'"; export CATALINA_OPTS; # Windows (catalina.bat) set JAVA_OPTS="-javaagent:classfinal-fatjar.jar='-pwd 000000'" ``` -------------------------------- ### Maven Plugin Integration for ClassFinal Source: https://context7.com/roseboy/classfinal/llms.txt Integrates ClassFinal into Maven projects by configuring the `classfinal-maven-plugin` in `pom.xml`. This automates the encryption process during the package phase of the build. It allows specifying passwords, packages to encrypt, configuration files, exclusions, and library dependencies directly within the Maven configuration. ```xml net.roseboy classfinal-maven-plugin 1.2.1 000000 com.yourpackage,com.yourpackage.service application.yml,application-prod.yml com.yourpackage.config.OpenConfig your-core-*.jar,your-utils.jar /path/to/tomcat/lib XXXXXXXXXXXXXX false package classFinal ``` -------------------------------- ### Encrypt JAR/WAR via Command Line Source: https://github.com/roseboy/classfinal/blob/master/README.md Use the ClassFinal fat JAR to encrypt your project artifacts. This command specifies the target file, packages to encrypt, and security parameters. ```sh java -jar classfinal-fatjar.jar -file yourpaoject.jar -libjars a.jar,b.jar -packages com.yourpackage,com.yourpackage2 -exclude com.yourpackage.Main -pwd 123456 -Y ``` -------------------------------- ### Configure Maven Plugin for Encryption Source: https://github.com/roseboy/classfinal/blob/master/README.md Integrate ClassFinal into your build lifecycle by adding the plugin to your pom.xml. This ensures that the encryption process occurs automatically during the package phase. ```xml net.roseboy classfinal-maven-plugin ${classfinal.version} 000000 com.yourpackage,com.yourpackage2 application.yml org.spring a.jar,b.jar package classFinal ``` -------------------------------- ### Configure Tomcat catalina.sh for ClassFinal Source: https://context7.com/roseboy/classfinal/llms.txt Configures the Java agent in Tomcat's catalina.sh to enable decryption at runtime. Supports both password-protected and no-password modes. ```shell export WAR_PASSWORD=MySecretPassword CATALINA_OPTS="$CATALINA_OPTS -javaagent:/path/to/classfinal-fatjar-1.2.1.jar='-pwdname WAR_PASSWORD'" export CATALINA_OPTS # 无密码模式启动 CATALINA_OPTS="$CATALINA_OPTS -javaagent:/path/to/classfinal-fatjar-1.2.1.jar='-nopwd'" export CATALINA_OPTS ``` -------------------------------- ### ClassFinal Machine Binding Feature Source: https://context7.com/roseboy/classfinal/llms.txt Restricts the execution of encrypted applications to specific machines by generating and utilizing a machine code. This provides an additional layer of security by hardware binding. The process involves generating a machine code on the target server and then using it during the encryption process. ```bash # Generate machine code on the target server java -jar classfinal-fatjar-1.2.1.jar -C # Output: Server code is: XXXXXXXXXXXXXX # Output: ==> /path/to/classfinal-code.txt # Encrypt using machine code (supports password + machine code dual verification) java -jar classfinal-fatjar-1.2.1.jar \ -file /path/to/yourproject.jar \ -packages com.yourpackage \ -code XXXXXXXXXXXXXX \ -pwd 123456 \ -Y # Encrypted JAR can only run on the server where the machine code was generated. # Running on another machine will prompt: "This project cannot be run on this machine!" ``` -------------------------------- ### Generate Machine Binding Code Source: https://github.com/roseboy/classfinal/blob/master/README.md Generate a unique machine code to bind the encrypted project to a specific server. This prevents the application from running on unauthorized hardware. ```sh java -jar classfinal-fatjar.jar -C ``` -------------------------------- ### Command-Line JAR/WAR Encryption with ClassFinal Source: https://context7.com/roseboy/classfinal/llms.txt Encrypts JAR or WAR files using the ClassFinal command-line tool. Supports various options like package filtering, excluding classes, encrypting dependencies and configuration files, and machine binding. The '-Y' flag indicates encryption. ```bash # Download ClassFinal tool wget https://repo1.maven.org/maven2/net/roseboy/classfinal-fatjar/1.2.1/classfinal-fatjar-1.2.1.jar # Basic encryption command - encrypt class files of specified package names java -jar classfinal-fatjar-1.2.1.jar \ -file /path/to/yourproject.jar \ -packages com.yourpackage,com.yourpackage2 \ -pwd 123456 \ -Y # Full encryption command - includes encryption of libs and config files java -jar classfinal-fatjar-1.2.1.jar \ -file /path/to/yourproject.jar \ -libjars dependency-a.jar,dependency-b.jar \ -packages com.yourpackage \ -exclude com.yourpackage.config.PublicConfig \ -cfgfiles application.yml,application.properties \ -classpath /path/to/external/libs \ -pwd MySecretPassword123 \ -Y # Use wildcards for package and file matching java -jar classfinal-fatjar-1.2.1.jar \ -file /path/to/yourproject.jar \ -packages com.myapp.*,net.roseboy.* \ -libjars mylib-*.jar \ -cfgfiles *.yml \ -pwd 123456 \ -Y # Output: yourproject-encrypted.jar ``` -------------------------------- ### ClassFinal Passwordless Encryption Mode Source: https://context7.com/roseboy/classfinal/llms.txt Enables passwordless encryption using a special password symbol '#'. The system generates a random password embedded within the encrypted package, eliminating the need for manual password input at runtime. This mode can be used for both JAR and WAR files. ```bash # Passwordless mode encryption of JAR package java -jar classfinal-fatjar-1.2.1.jar \ -file /path/to/yourproject.jar \ -packages com.yourpackage \ -pwd '#' \ -Y # Start passwordless encrypted JAR package java -javaagent:yourproject-encrypted.jar -jar yourproject-encrypted.jar # Passwordless mode encryption of WAR package java -jar classfinal-fatjar-1.2.1.jar \ -file /path/to/yourproject.war \ -packages com.yourpackage \ -pwd '#' \ -Y # Start passwordless encrypted WAR in Tomcat (catalina.sh) export CATALINA_OPTS="$CATALINA_OPTS -javaagent:/path/to/classfinal-fatjar-1.2.1.jar='-nopwd'" ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.