Created
August 15, 2018 13:07
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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