Step 1. Add the JitPack repository to your build file
Add it in your root settings.gradle at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Add it in your settings.gradle.kts at the end of repositories:
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
mavenCentral()
maven { url = uri("https://jitpack.io") }
}
}
Add to pom.xml
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Add it in your build.sbt at the end of resolvers:
resolvers += "jitpack" at "https://jitpack.io"
Add it in your project.clj at the end of repositories:
:repositories [["jitpack" "https://jitpack.io"]]
Step 2. Add the dependency
dependencies {
implementation 'com.github.akivamu:libgdx-crypt-texture:1.0.0'
}
dependencies {
implementation("com.github.akivamu:libgdx-crypt-texture:1.0.0")
}
<dependency>
<groupId>com.github.akivamu</groupId>
<artifactId>libgdx-crypt-texture</artifactId>
<version>1.0.0</version>
</dependency>
libraryDependencies += "com.github.akivamu" % "libgdx-crypt-texture" % "1.0.0"
:dependencies [[com.github.akivamu/libgdx-crypt-texture "1.0.0"]]
A simple library to encrypt and decrypt files (include libGdx Texture)
Update 2018
For convenience, use this gradle plugin. Ignore below steps.
Step 1. Use other tools to create texture file (e.g. TexturePacker)
Step 2. Encrypt generated texture files by libgdx-crypt-texture
executable jar.
Step 3. In libGdx project source code:
Texture
, decrypting by TextureDecryptor
CryptTextureAtlas
to create skinThe class TextureEncryptor
should be used in dev PC only.
You can build this project into executable jar file, then run on command line to encrypt files.
Command line arguments:
SimpleXorCrypto
algorithm.Use class TextureDecryptor
to decrypt file, passing your specific crypto implementation.
// Your secret key to encrypt
int secretKey = 123;
// Use simple crypto implementation
Crypto crypto = new SimpleXorCrypto((byte) secretKey);
// Decrypt texture file
Texture decrypted = TextureDecryptor.loadTexture(crypto, "encrypted_texture_file.png");
Make your custom encrypting algorithm by implementing this interface.
public interface Crypto {
byte[] encrypt(byte[] bytes, boolean inPlace);
byte[] decrypt(byte[] bytes, boolean inPlace);
}
The library provides a sample algorithm implementation called SimpleXorCrypto
.
LibGdx Skin
uses texture atlas to manage textures, texture regions, drawable...
The class CryptTextureAtlas
extends libGdx's class TextureAtlas
, adding crypto function
We use it when initialize Skin
// An example crypto
int secretKey = 123;
Crypto crypto = new SimpleXorCrypto((byte) secretKey);
// Decrypt texture file into texture atlas
CryptTextureAtlas atlas = new CryptTextureAtlas(crypto, "yourAtlas.pack");
// Load into skin
Skin skin = new Skin(yourSkinFile, atlas);
The project use gradle with java plugin, everything is as normal. To build executable jar, run shadowJar:
gradlew shadowJar
Output jar is in ./build/libs folder