Skip to content

Instantly share code, notes, and snippets.

@hendrawd
Created August 15, 2018 13:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hendrawd/d3f347935e980e40907a005cd44a659a to your computer and use it in GitHub Desktop.
Save hendrawd/d3f347935e980e40907a005cd44a659a to your computer and use it in GitHub Desktop.
An helper method for creating byte url from a string url, then we can copy the result from the console to the actual code
/**
* An helper method for creating byte url from a string url,
* then we can copy the result from the console to the actual code.
* This is useful for fighting against reverse engineering in java/android apps.
* Can be combined with other methods to make your apps more secure.
* Just keep in mind that there is no ways to win against a determined hacker,
* so do all of critical processes in server
*/
public final class ByteUrlGenerator {
public static void main(String[] args) {
System.out.println(byteUrlGenerator("https://hendrawd.github.io"));
}
public static String byteUrlGenerator(String originalUrl) {
if (originalUrl == null || originalUrl.equals("")) {
return "";
}
byte[] bytesFromOriginalString = originalUrl.getBytes();
StringBuilder stringBuilder = new StringBuilder("{");
for (byte urlByte : bytesFromOriginalString) {
stringBuilder.append(urlByte);
stringBuilder.append(", ");
}
stringBuilder.delete(stringBuilder.length() - 2, stringBuilder.length());
stringBuilder.append("};");
return stringBuilder.toString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment