Step 15 - Custom String Encryption

This is Step 1 modified to use custom string encryption.
custom.jar contains a class with sample encryption/decryption methods along with the source code.

Changes in configuration file are in bold:

<config>
    <input>
        <jar in="test.jar" out="obf-test.jar"/>
        <jar in="mousegestures-1.2.jar" out="obf-mousegestures-1.2.jar"/>

        <jar in="custom.jar" out="obf-custom.jar"/>
    </input>

    <-names>
        <class access="protected+">
            <field access="protected+"/>
            <method access="protected+"/>
        </class>
    </keep-names>

    <!-- We recommend using the v3 setting if custom string encryption is applied to ALL your classes. -->
    <!-- This way Allatori would not add any additional (unused) string decryption methods. -->
    <!-- If you combine custom string encryption and Allatori string encryption, then the default v4 setting is recommended. -->
    <property name="string-encryption-version" value="v3"/>

    <!-- Disabling string encryption in custom decryption methods, as it could lead to infinite recursive calls. -->
    <property name="string-encryption" value="disable" apply2class="class com.allatori.custom.EncryptDecryptString" apply2method="decrypt*(java.lang.String)"/>

    <property name="string-encryption" value="maximum"/>
    <property name="string-encryption-type" value="custom(com.allatori.custom.EncryptDecryptString.encryptString, com.allatori.custom.EncryptDecryptString.decryptString)"/>

    <property name="log-file" value="log.xml"/>
</config>


You can combine Allatori string encryption with custom string encryption. Applying custom string encryption to classes in com.some.package only:
    <property name="string-encryption-type" value="custom(package.EncryptClassName.encryptMethodName, package.DecryptClassName.decryptMethodName)" apply2class="class com.some.package.*"/>


You can use multiple string encryption/decryption methods:
    <property name="string-encryption-type" value="custom(package.EncryptClassName1.encryptMethodName1, package.DecryptClassName1.decryptMethodName1)" apply2class="class com.some.package.*"/>
    <property name="string-encryption-type" value="custom(package.EncryptClassName2.encryptMethodName2, package.DecryptClassName2.decryptMethodName2)" apply2class="class com.some.other.package.*"/>
    <!-- Methods for classes not matched by the rules above -->
    <property name="string-encryption-type" value="custom(package.EncryptClassName3.encryptMethodName3, package.DecryptClassName3.decryptMethodName3)"/>


Encryption methods are needed during obfuscation only, they are not needed in the runtime of your application. They could be located in a separate jar file not included in your distribution.

Decryption methods are needed in the runtime, you can put them in any classes of your application.

Custom string encryption feature could be used for internationalization, as Allatori will wrap all string literals (if string encryption is set to maximum) with methodCall("String literal"). You can log all strings in the encryption method, translate them, and decryption method will replace strings with internationalized version in the runtime.

Step 14       Contents