### Hashids Decoding Failure with Different Salt Source: https://github.com/yomorun/hashids-java/blob/master/README.md This example illustrates that decoding a hash string requires the precise salt value used during encoding. If a different salt is provided, the `decode` method will return an empty array, indicating a decoding failure. ```Java Hashids hashids = new Hashids("this is my pepper"); long[] numbers = hashids.decode("NkK9"); ``` -------------------------------- ### Encode a Single Long Number using Hashids Source: https://github.com/yomorun/hashids-java/blob/master/README.md This example demonstrates how to encode a single long integer into a hash string using Hashids. A unique salt value is provided during initialization to ensure your generated hashes differ from others. The `encode` method returns the hash string. ```Java Hashids hashids = new Hashids("this is my salt"); String hash = hashids.encode(12345L); ``` -------------------------------- ### Encode Incremented Number Sequences with Hashids-Java Source: https://github.com/yomorun/hashids-java/blob/master/README.md This example illustrates how Hashids-Java encodes a sequence of incrementing numbers. The generated hash appears random and does not expose the sequential order of the input numbers (e.g., 1, 2, 3, ...), making it suitable for obfuscating database IDs or similar sequential data. ```Java Hashids hashids = new Hashids("this is my salt"); String hash = hashids.encode(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L); ``` -------------------------------- ### Import Hashids Package in Java Source: https://github.com/yomorun/hashids-java/blob/master/README.md Before using the Hashids class in your Java code, you need to import its package. This line allows you to reference the `Hashids` class directly without its fully qualified name. ```Java import org.hashids; ``` -------------------------------- ### Add Hashids.java Maven Dependency Source: https://github.com/yomorun/hashids-java/blob/master/README.md To include Hashids.java in a Maven project, add this dependency block to your `pom.xml` file within the `` section. This makes the library available for use in your Java application. ```XML org.hashids hashids 1.0.3 ``` -------------------------------- ### Add Hashids.java Gradle Dependency Source: https://github.com/yomorun/hashids-java/blob/master/README.md For Gradle or Android projects, add this `compile` dependency to your app's `build.gradle` file under the `dependencies` section. This integrates the Hashids library into your project. ```Groovy compile 'org.hashids:hashids:1.0.3' ``` -------------------------------- ### Decode Hashids String with Minimum Length Setting Source: https://github.com/yomorun/hashids-java/blob/master/README.md When decoding a hash that was generated with a minimum length, you must initialize the `Hashids` object with the same salt and minimum length. This ensures the decoding algorithm correctly processes the hash. ```Java Hashids hashids = new Hashids("this is my salt", 8); long[] numbers = hashids.decode("gB0NV05e"); ``` -------------------------------- ### Encode Repeating Numbers with Hashids-Java Source: https://github.com/yomorun/hashids-java/blob/master/README.md This snippet demonstrates how Hashids-Java encodes multiple identical numbers. The resulting hash does not reveal the repetition of the input numbers, ensuring that patterns like '5, 5, 5, 5' are obscured in the output hash, maintaining its non-sequential and unpredictable nature. ```Java Hashids hashids = new Hashids("this is my salt"); String hash = hashids.encode(5L, 5L, 5L, 5L); ``` -------------------------------- ### Encode Single Incrementing Numbers with Hashids-Java Source: https://github.com/yomorun/hashids-java/blob/master/README.md This snippet shows the encoding of individual incrementing numbers using Hashids-Java. Each number produces a unique and short hash, which is useful for creating distinct, non-sequential identifiers for entities like user IDs, even when the original numbers are sequential. ```Java Hashids hashids = new Hashids("this is my salt"); String hash1 = hashids.encode(1L); /* NV */ String hash2 = hashids.encode(2L); /* 6m */ String hash3 = hashids.encode(3L); /* yD */ String hash4 = hashids.encode(4L); /* 2l */ String hash5 = hashids.encode(5L); /* rD */ ``` -------------------------------- ### Encode and Decode MongoDB Hex IDs with Hashids Source: https://github.com/yomorun/hashids-java/blob/master/README.md Hashids provides dedicated methods (`encodeHex` and `decodeHex`) for handling hexadecimal IDs, such as those generated by MongoDB. Note that the algorithm for hex IDs is separate and not compatible with the standard long integer encoding/decoding methods. ```Java Hashids hashids = new Hashids("This is my salt"); String hash = hashids.encodeHex("507f1f77bcf86cd799439011"); // goMYDnAezwurPKWKKxL2 String objectId = hashids.decodeHex(hash); // 507f1f77bcf86cd799439011 ``` -------------------------------- ### Decode a Hashids String to Numbers Source: https://github.com/yomorun/hashids-java/blob/master/README.md To retrieve the original numbers from a hash string, use the `decode` method. It's crucial to use the exact same salt value that was used during encoding, otherwise decoding will fail. The method returns an array of long integers. ```Java Hashids hashids = new Hashids("this is my salt"); long[] numbers = hashids.decode("NkK9"); ``` -------------------------------- ### Encode Number with Minimum Hash Length in Hashids Source: https://github.com/yomorun/hashids-java/blob/master/README.md You can specify a minimum length for the generated hash by passing an additional argument to the `Hashids` constructor. This ensures the output hash string is at least the specified length, padding if necessary. The default minimum length is 0. ```Java Hashids hashids = new Hashids("this is my salt", 8); String hash = hashids.encode(1L); ``` -------------------------------- ### Decode Multiple Numbers from Hashids String Source: https://github.com/yomorun/hashids-java/blob/master/README.md Similar to encoding, decoding a hash string that contains multiple numbers is done using the `decode` method with the correct salt. The method returns an array of long integers in their original order. ```Java Hashids hashids = new Hashids("this is my salt"); long[] numbers = hashids.decode("aBMswoO2UB3Sj"); ``` -------------------------------- ### Encode Multiple Long Numbers using Hashids Source: https://github.com/yomorun/hashids-java/blob/master/README.md Hashids can encode multiple long integers into a single hash string. Pass all the numbers as arguments to the `encode` method. The order of numbers is preserved during encoding and decoding. ```Java Hashids hashids = new Hashids("this is my salt"); String hash = hashids.encode(683L, 94108L, 123L, 5L); ``` -------------------------------- ### Encode Number with Custom Hash Alphabet in Hashids Source: https://github.com/yomorun/hashids-java/blob/master/README.md Hashids allows you to define a custom alphabet for the generated hashes. This can be useful for restricting characters or for specific formatting requirements. The alphabet is passed as the third argument to the `Hashids` constructor. ```Java Hashids hashids = new Hashids("this is my salt", 0, "0123456789abcdef"); String hash = hashids.encode(1234567L); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.